Skip to content

Commit 2035737

Browse files
committed
More clearly document Stdin::read_line
These are common pitfalls for beginners, so I think it's worth making the subtleties more visible.
1 parent 4cc494b commit 2035737

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/std/src/io/stdio.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,12 @@ impl Stdin {
370370
/// Locks this handle and reads a line of input, appending it to the specified buffer.
371371
///
372372
/// For detailed semantics of this method, see the documentation on
373-
/// [`BufRead::read_line`].
373+
/// [`BufRead::read_line`]. In particular:
374+
/// * Previous content of the buffer will be preserved. To avoid appending
375+
/// to the buffer, you need to [`clear`] it first.
376+
/// * The trailing newline character, if any, is included in the buffer.
377+
///
378+
/// [`clear`]: String::clear
374379
///
375380
/// # Examples
376381
///

0 commit comments

Comments
 (0)