diff options
| author | bors <bors@rust-lang.org> | 2024-10-23 22:28:57 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-23 22:28:57 +0000 | 
| commit | b8bb2968ce1e44d01520c9d59ee6299ed66df3f9 (patch) | |
| tree | 82ca49a2923c40b61c67ae4a6508390d25ec2a49 /library/std/src | |
| parent | 4f2f477fded0a47b21ed3f6aeddeafa5db8bf518 (diff) | |
| parent | fbe33e35aff61910178565013a7efbb4840e7629 (diff) | |
| download | rust-b8bb2968ce1e44d01520c9d59ee6299ed66df3f9.tar.gz rust-b8bb2968ce1e44d01520c9d59ee6299ed66df3f9.zip | |
Auto merge of #132079 - fmease:rollup-agrd358, r=fmease
Rollup of 9 pull requests
Successful merges:
 - #130991 (Vectorized SliceContains)
 - #131928 (rustdoc: Document `markdown` module.)
 - #131955 (Set `signext` or `zeroext` for integer arguments on RISC-V and LoongArch64)
 - #131979 (Minor tweaks to `compare_impl_item.rs`)
 - #132036 (Add a test case for #131164)
 - #132039 (Specialize `read_exact` and `read_buf_exact` for `VecDeque`)
 - #132060 ("innermost", "outermost", "leftmost", and "rightmost" don't need hyphens)
 - #132065 (Clarify documentation of `ptr::dangling()` function)
 - #132066 (Fix a typo in documentation of `pointer::sub_ptr()`)
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/io/impls.rs | 46 | 
1 files changed, 46 insertions, 0 deletions
| diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 85023540a81..b952c85addf 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -453,6 +453,29 @@ impl<A: Allocator> Read for VecDeque<u8, A> { Ok(n) } + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let (front, back) = self.as_slices(); + + // Use only the front buffer if it is big enough to fill `buf`, else use + // the back buffer too. + match buf.split_at_mut_checked(front.len()) { + None => buf.copy_from_slice(&front[..buf.len()]), + Some((buf_front, buf_back)) => match back.split_at_checked(buf_back.len()) { + Some((back, _)) => { + buf_front.copy_from_slice(front); + buf_back.copy_from_slice(back); + } + None => { + self.clear(); + return Err(io::Error::READ_EXACT_EOF); + } + }, + } + + self.drain(..buf.len()); + Ok(()) + } + #[inline] fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { let (ref mut front, _) = self.as_slices(); @@ -462,6 +485,29 @@ impl<A: Allocator> Read for VecDeque<u8, A> { Ok(()) } + fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { + let len = cursor.capacity(); + let (front, back) = self.as_slices(); + + match front.split_at_checked(cursor.capacity()) { + Some((front, _)) => cursor.append(front), + None => { + cursor.append(front); + match back.split_at_checked(cursor.capacity()) { + Some((back, _)) => cursor.append(back), + None => { + cursor.append(back); + self.clear(); + return Err(io::Error::READ_EXACT_EOF); + } + } + } + } + + self.drain(..len); + Ok(()) + } + #[inline] fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> { // The total len is known upfront so we can reserve it in a single call. | 
