-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add read_into_buf and get_buf to BufRead #1015
Conversation
I always assumed |
An implementation is currently used in hyper. It was unfortunate needing to copy the BufReader from std, since otherwise the |
This is a particularly useful pattern for high performance parsing. For example, one of the tricks rapidjson does to speed up parsing is to use SIMD instructions to parse N whitespace characters at a time. We could use this trick if we could get access to the underlying |
@erickt that's pretty much my exact usecase (except parsing HTTP instead of JSON). |
I think this RFC as written proposes a backwards incompatible change, yes? Existing implementations of Is there a way to salvage the RFC? (I don't see any obvious way to provide default impls of these methods.) |
I don't believe a default could be provided for these methods. To salvage this, it would need... to be a new trait? |
|
||
/// This will read from the inner Read, and append the data onto the end of | ||
/// any currently buffered data. | ||
fn read_into_buf(&mut self) -> io::Result<usize>; |
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.
The return value is... how much data is currently in the buffer, or how much was read by just this call?
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.
It returns how much was read by this call. You can check the size of the current buffer with get_buf().len()
.
This RFC is now entering its week-long final comment period. |
I agree with @seanmonstar's analysis that this can no longer be implemented (due to stabilization), and it doesn't seem worth it to add an extra trait at this time. |
Something I thought of also, would be to provide default implementations with This solution would allow adding methods to any trait. |
I've wanted this exact functionality myself, so 👍 to the idea. It'll be nice if we can find a way to add this functionality in a backward-compatible way, but if not, I think this should be a strong contender for adding in 2.0. |
The consensus of the libs team was to close this RFC at this time. We think that extension traits should bake outside the standard library first, and otherwise it looks like this RFC may want to start anew with a fresh look at backwards-compatibility. Thanks regardless for the RFC @seanmonstar! |
Add two methods to
BufRead
,read_into_buf
andget_buf
. These would allow filling up more of the buffer, and inspecting the buffered data without causing an implicit read.Rendered
cc @aturon @alexcrichton @sfackler