From fca091985c1cddf1a4214dd449cfa5119089300b Mon Sep 17 00:00:00 2001 From: "Tim (Theemathas) Chirananthavat" Date: Thu, 10 Oct 2024 23:12:03 +0700 Subject: [PATCH] More clearly document Stdin::read_line These are common pitfalls for beginners, so I think it's worth making the subtleties more visible. --- std/src/io/stdio.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/std/src/io/stdio.rs b/std/src/io/stdio.rs index bf242e715bd94..35b38ed783ff2 100644 --- a/std/src/io/stdio.rs +++ b/std/src/io/stdio.rs @@ -370,7 +370,12 @@ impl Stdin { /// Locks this handle and reads a line of input, appending it to the specified buffer. /// /// For detailed semantics of this method, see the documentation on - /// [`BufRead::read_line`]. + /// [`BufRead::read_line`]. In particular: + /// * Previous content of the buffer will be preserved. To avoid appending + /// to the buffer, you need to [`clear`] it first. + /// * The trailing newline character, if any, is included in the buffer. + /// + /// [`clear`]: String::clear /// /// # Examples ///