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

clarify BufRead::{fill_buf, consume} docs #136177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hkBst
Copy link
Member

@hkBst hkBst commented Jan 28, 2025

Fixes #85394

@rustbot
Copy link
Collaborator

rustbot commented Jan 28, 2025

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 28, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@ibraheemdev ibraheemdev left a 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.
Copy link
Member

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.

Copy link
Member Author

@hkBst hkBst Feb 19, 2025

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.

Comment on lines -2269 to +2264
/// 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.
Copy link
Member

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.

Copy link
Member Author

@hkBst hkBst Feb 19, 2025

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// 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.

Copy link
Member Author

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.
Copy link
Member

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.

Copy link
Member Author

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"?

Comment on lines +2293 to +2294
/// 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.
Copy link
Member

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?

Suggested change
/// 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`.
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Suggested change
/// 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 rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2025
@hkBst
Copy link
Member Author

hkBst commented Mar 2, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation for BufRead is confusing
4 participants