-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
clarify BufRead::{fill_buf, consume} docs #136177
base: master
Are you sure you want to change the base?
Conversation
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the primary change here, but unsure about some of the other changes.
@@ -2250,24 +2250,18 @@ fn skip_until<R: BufRead + ?Sized>(r: &mut R, delim: u8) -> Result<usize> { | |||
/// ``` | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
pub trait BufRead: Read { | |||
/// Returns the contents of the internal buffer, filling it with more data | |||
/// from the inner reader if it is empty. | |||
/// Returns the contents of the internal buffer, filling it with more data, via Read methods, if empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is better. I would prefer the "inner reader" wording.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found "inner reader" confusing, since it sounds like a member of a struct, while it is actually a supertrait of this trait.
/// This function will return an I/O error if the underlying reader was | ||
/// read, but returned an error. | ||
/// Passes on I/O errors from Read. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly not sure if this is an improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reasoning as for "inner reader", and more direct, though perhaps something like "its supertrait Read" would make this better?
/// Tells this buffer that `amt` bytes have been consumed from the buffer, | ||
/// so they should no longer be returned in calls to `read`. | ||
/// Marks the given `amount` of additional bytes from the internal buffer as having been read. | ||
/// Subsequent calls to `read` return bytes that have not yet been so marked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Subsequent calls to `read` return bytes that have not yet been so marked. | |
/// Subsequent calls to `read` will not return bytes that have been marked as consumed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like to avoid phrasing this as a negative, and instead say what read
will do as opposed to what it won't. Perhaps this would be better if "so marked" => "marked as read"?
/// | ||
/// [`consume`]: BufRead::consume | ||
/// | ||
/// An empty buffer returned indicates that the stream has reached EOF. | ||
/// Returns an empty buffer to indicate that the stream has reached EOF. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a specific return condition, the new wording makes it sound like it always returns an empty buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point. Perhaps "to indicate that" => "when"?
/// This is a lower-level method and is meant to be used together with [`fill_buf`], | ||
/// which can be used to fill the internal buffer via Read methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep some of the extra context from the original?
/// This is a lower-level method and is meant to be used together with [`fill_buf`], | |
/// which can be used to fill the internal buffer via Read methods. | |
/// This is a lower-level method and is meant to be used together with [`fill_buf`], | |
/// which can be used to fill the internal buffer via `Read` methods. This function does | |
/// not perform any I/O, it simply informs this object that some amount of | |
/// its buffer, returned from [`fill_buf`], has been consumed and should | |
/// no longer be returned. |
|
||
/// Checks if the underlying `Read` has any data left to be read. | ||
/// Checks if there is any data left to be `read`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also prefer the "underlying reader" wording here.
@@ -2324,6 +2313,10 @@ pub trait BufRead: Read { | |||
/// returned slice is empty (which means that there is no data left, | |||
/// since EOF is reached). | |||
/// | |||
/// # Errors | |||
/// | |||
/// Passes on I/O errors from Read. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
/// Passes on I/O errors from Read. | |
/// This function will return an I/O error if the underlying reader was | |
/// read, but returned an error. |
@rustbot ready |
Fixes #85394