Skip to content

Commit f70779b

Browse files
committed
Auto merge of rust-lang#110604 - a1phyr:vecdeque_buf_read, r=dtolnay
Implement `BufRead` for `VecDeque<u8>` Note: it would become insta-stable
2 parents 64368d0 + a9ece12 commit f70779b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: library/std/src/io/impls.rs

+18
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,24 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
475475
}
476476
}
477477

478+
/// BufRead is implemented for `VecDeque<u8>` by reading bytes from the front of the `VecDeque`.
479+
#[stable(feature = "vecdeque_buf_read", since = "CURRENT_RUSTC_VERSION")]
480+
impl<A: Allocator> BufRead for VecDeque<u8, A> {
481+
/// Returns the contents of the "front" slice as returned by
482+
/// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are
483+
/// discontiguous, multiple calls to `fill_buf` will be needed to read the entire content.
484+
#[inline]
485+
fn fill_buf(&mut self) -> io::Result<&[u8]> {
486+
let (front, _) = self.as_slices();
487+
Ok(front)
488+
}
489+
490+
#[inline]
491+
fn consume(&mut self, amt: usize) {
492+
self.drain(..amt);
493+
}
494+
}
495+
478496
/// Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed.
479497
#[stable(feature = "vecdeque_read_write", since = "1.63.0")]
480498
impl<A: Allocator> Write for VecDeque<u8, A> {

0 commit comments

Comments
 (0)