Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the explanation about the behaviour of read_line #94957

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,8 @@ pub trait BufRead: Read {
}

/// Read all bytes until a newline (the `0xA` byte) is reached, and append
/// them to the provided buffer.
/// them to the provided buffer. You do not need to clear the buffer before
/// appending.
Comment on lines +2113 to +2114
Copy link
Member

@m-ou-se m-ou-se Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes it sound more confusing than before.

You do not need to clear the buffer before appending.

This could be interpreted as: you don't need to clear it, because it happens automatically.

Note that rust-lang/book#2574 is about the Rust Book, not about the standard library documentation. The std documentation before this change already clearly states that this function appends the data.

///
/// This function will read bytes from the underlying stream until the
/// newline delimiter (the `0xA` byte) or EOF is found. Once found, all bytes
Expand Down