-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Discrepancy between docs and implementation of BufReader::fill_buf #48022
Comments
Adding a method to I would love it if we can make "every time this is called, the implementation should fetch more data" part of the |
Well, even that is tricky, right? What if the buffer is already full? I also think there's value in being able to get access to the bytes currently in the buffer without doing a syscall (something like |
The issue is that you can't really do anything to the structure of the |
I guess one question is where we decide to not expand |
I also ran into this 'faulty' documentation issue. |
The proposed behavior is fundamentally broken. Imagine a You call Now you call |
Just to clarify, is the idea here to update the
...into something like this?
|
Ah, @sfackler commented while I was writing my comment and answered a couple of the questions I had 👍 |
I'd probably phrase it as
|
@sfackler I agree with you that changing the behavior of I do think there's an argument for providing a method that gives the buffer contents without ever doing a syscall, but that's probably an argument for another issue. |
I'm happy to mentor anyone who wants to fix this issue! Here's how: The line in question is here: Line 1376 in 52ed3d8
This should be changed to:
I'm happy to answer any additional questions! |
Perhaps we should also include a reference to the newly added |
Update documentation for fill_buf in std::io::BufRead Brings the documentation in line with the BufReader implementation. Fixes rust-lang#48022. This is my first PR, and I think the `E-easy` label is very cool, as so is the practice of describing the fix but leaving it for someone else; it really makes it a lot less intimidating to get started with something!
Would you like to fix this bug? If so, here's how.
The documentation currently states that
BufRead::fill_buf
:However, this is not what
BufReader
's implementation of that method does. It will only fill the buffer if no data is currently buffered. If data is already present in the buffer, no filling takes place:I would argue that the current behavior of
BufReader
's implementation is usually what users would want to do, but if does not match the documentation of, nor the name of,fill_buf
. I don't know what the right solution here is, but I suspect the only safe thing to do would be to updateBufReader
's implementation to match the docs (i.e., to make it actually fill its buffer), and then to add another method toBufRead
(perhapsbuf_bytes
?) that gives the currently buffered contents, regardless of the amount of buffered data, and without reading from the underlyingRead
.The text was updated successfully, but these errors were encountered: