Skip to content

Commit b1cd526

Browse files
borsestebank
authored andcommitted
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 b1cd526

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

library/std/src/io/impls.rs

Lines changed: 18 additions & 0 deletions
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> {

tests/run-make/dump-ice-to-disk/check.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export RUSTC_ICE=$TMPDIR
1111
$RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-default-set.log 2>&1
1212
default_set=$(cat $TMPDIR/rustc-ice-*.txt | wc -l)
1313
content=$(cat $TMPDIR/rustc-ice-*.txt)
14+
# Ensure that the ICE dump path doesn't contain `:` because they cause problems on Windows
15+
windows_safe=$(echo rustc-ice-*.txt | grep ':')
16+
if [ ! -z "$windows_safe" ]; then
17+
exit 1
18+
fi
19+
1420
rm $TMPDIR/rustc-ice-*.txt
1521
RUST_BACKTRACE=short $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-short.log 2>&1
1622
short=$(cat $TMPDIR/rustc-ice-*.txt | wc -l)

0 commit comments

Comments
 (0)