Skip to content

Commit

Permalink
Auto merge of rust-lang#110604 - a1phyr:vecdeque_buf_read, r=dtolnay
Browse files Browse the repository at this point in the history
Implement `BufRead` for `VecDeque<u8>`

Note: it would become insta-stable
  • Loading branch information
bors authored and estebank committed Oct 16, 2023
2 parents 64368d0 + a9ece12 commit b1cd526
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions library/std/src/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
6 changes: 6 additions & 0 deletions tests/run-make/dump-ice-to-disk/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export RUSTC_ICE=$TMPDIR
$RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-default-set.log 2>&1
default_set=$(cat $TMPDIR/rustc-ice-*.txt | wc -l)
content=$(cat $TMPDIR/rustc-ice-*.txt)
# Ensure that the ICE dump path doesn't contain `:` because they cause problems on Windows
windows_safe=$(echo rustc-ice-*.txt | grep ':')
if [ ! -z "$windows_safe" ]; then
exit 1
fi

rm $TMPDIR/rustc-ice-*.txt
RUST_BACKTRACE=short $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-short.log 2>&1
short=$(cat $TMPDIR/rustc-ice-*.txt | wc -l)
Expand Down

0 comments on commit b1cd526

Please sign in to comment.