-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tracking Issue for bufreader_peek
#128405
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
Comments
bufreader_peek
@rustbot claim starting work on implementation |
…k-Simulacrum implement BufReader::peek Part of rust-lang#128405
…k-Simulacrum implement BufReader::peek Part of rust-lang#128405
…k-Simulacrum implement BufReader::peek Part of rust-lang#128405
Rollup merge of rust-lang#128406 - lolbinarycat:bufreader_peek, r=Mark-Simulacrum implement BufReader::peek Part of rust-lang#128405
implement BufReader::peek Part of rust-lang/rust#128405
calling |
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
…d, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
Rollup merge of rust-lang#129675 - lolbinarycat:bufreader_peek_unsized, r=workingjubilee allow BufReader::peek to be called on unsized types rust-lang#128405
Fix crash in BufReader::peek() `bufreader_peek` tracking issue: rust-lang#128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
Fix crash in BufReader::peek() `bufreader_peek` tracking issue: rust-lang#128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
Fix crash in BufReader::peek() `bufreader_peek` tracking issue: rust-lang#128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
Fix crash in BufReader::peek() `bufreader_peek` tracking issue: rust-lang#128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
Fix crash in BufReader::peek() `bufreader_peek` tracking issue: rust-lang#128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
Rollup merge of rust-lang#137832 - wgwoods:fix-bufreader-peek, r=joboet Fix crash in BufReader::peek() `bufreader_peek` tracking issue: rust-lang#128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
Fix crash in BufReader::peek() `bufreader_peek` tracking issue: rust-lang#128405 This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
…onsume, r=Mark-Simulacrum doc: clarify that consume can be called after BufReader::peek tracking issue rust-lang#128405
Rollup merge of rust-lang#137890 - lolbinarycat:docs-bufreader-peek-consume, r=Mark-Simulacrum doc: clarify that consume can be called after BufReader::peek tracking issue rust-lang#128405
…onsume, r=Mark-Simulacrum doc: clarify that consume can be called after BufReader::peek tracking issue rust-lang#128405
This came up when decoding base64 (and same thing with hex or anything similar). Some insight:
|
@Kixunil you can retrieve the buffer size by calling I'm not sure if you're providing feedback on the feature as implemented or are advocating for its eventual stabilization. |
I know, but I can't do that for any I'm advocating for abstracting it into its own trait and implementing it for other types. I'm also saying "this is not useless". |
The problem is |
Yes, we would need something like: pub trait Peek: BufRead {
/// Returns the maximum number of bytes that can be held in an internal buffer.
///
/// Returns `None` for "infinity". That doesn't mean there will be infinite bytes available. `peek` can still return fewer than requested amount of bytes if the stream is at end. It only means that any requested amount is valid.
fn capacity(&self) -> Option<usize>;
/// Fills the internal buffer to have *at least* `requested_bytes` bytes if possible.
///
/// This will return a slice that has length of at least `requested_bytes` unless the stream reached the end or the internal buffer is full.
/// If the internal buffer is longer the reader may request more bytes than requested an return them too.
/// Call the consume() method to inform the reader about how many bytes were consumed.
fn peek(&mut self, requested_bytes: usize) -> io::Result<&[u8]>;
}
// impl Peek for &[u8], Cursor, BufReader Then the decoders would use this bound instead of purely |
You would have to open a new ACP for that. |
Sorry if this is the wrong place to ask, but have alternative names been considered? Currently, the Meanwhile I'm not sure what the most intuitive name would be, but perhaps something like |
The difference is that fill_buf is a low-level primitive, meant as a building block for other operations, while peek is a useful function by itself. The fact that While their implementations are similar, their semantics and intended usecase are not. Using the term "peek" for "look ahead in a stream without advancing it" is a well-established programming convention. At a quick glance i found Rust typically follows existing naming conbentions where applicable, it's why |
I don't want to get too philosophical but since you can implement Anyway, the name But that can be improved by changing the short doc to say "Attempts to fill the buffer with at least |
Actually a lot of low-level functions can be implemented trivially if you already have a higher-level function. If you already have an implementation for
I would argue this is an X/Y problem. Filling the buffer is not itself a useful operation, but is instead the means to an end. I'm curious why you would want to fill the buffer if not to look ahead in the stream? |
It is a question of consistent terminology. The existing |
Only if you're writing one byte at a time which is quite less performant compared to my
To have at least 4 bytes of base64 to pass into a decoding function. (The decoding function can take more but taking less would confuse it.)
Exactly. |
|
What I mean is that if you have a writer that never performs partial writes, you can implement
Why not just read 4 bytes at a time?
Aren't most operations on buffered streams very similar? Even if Even if I wanted it renamed, I have no authority in that decision. The only productive options you have at this point are to either to suggest a documentation change that clarifies this while also matching the semantics of |
I'm not excited about either of those but I could imagine doing so if there is any better. |
ACP 569 which proposes to generalize this to a trait also proposes a bit more general API in that the |
@the8472 yeah, I didn't consider stuff like slices when I was writing my original proposal, eliminating that copy within generic code does seem worthwhile. |
Feature gate:
#![feature(bufreader_peek)]
This is a tracking issue for the
BufReader::peek
method.Public API
Steps / History
Unresolved Questions
n
>capacity
? options are: short slice, error, or panic.Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: