diff options
| author | bors <bors@rust-lang.org> | 2023-10-15 19:15:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-15 19:15:01 +0000 |
| commit | f70779b0fb250655150d5a4dabe59acf4cf36cf6 (patch) | |
| tree | b84595afec3beb937f8d0cedb61056f82fa0110e | |
| parent | 64368d0279c41699fffd7980304488d65a42ba32 (diff) | |
| parent | a9ece1255bf25dbc95598b35d407789cf38883d0 (diff) | |
| download | rust-f70779b0fb250655150d5a4dabe59acf4cf36cf6.tar.gz rust-f70779b0fb250655150d5a4dabe59acf4cf36cf6.zip | |
Auto merge of #110604 - a1phyr:vecdeque_buf_read, r=dtolnay
Implement `BufRead` for `VecDeque<u8>` Note: it would become insta-stable
| -rw-r--r-- | library/std/src/io/impls.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index a7428776d8f..f438325560f 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -475,6 +475,24 @@ impl<A: Allocator> Read for VecDeque<u8, A> { } } +/// BufRead is implemented for `VecDeque<u8>` by reading bytes from the front of the `VecDeque`. +#[stable(feature = "vecdeque_buf_read", since = "CURRENT_RUSTC_VERSION")] +impl<A: Allocator> BufRead for VecDeque<u8, A> { + /// Returns the contents of the "front" slice as returned by + /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are + /// discontiguous, multiple calls to `fill_buf` will be needed to read the entire content. + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { + let (front, _) = self.as_slices(); + Ok(front) + } + + #[inline] + fn consume(&mut self, amt: usize) { + self.drain(..amt); + } +} + /// Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] impl<A: Allocator> Write for VecDeque<u8, A> { |
