diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-02-12 20:10:01 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-12 20:10:01 -0500 |
| commit | de712f9e0af724f513e3b8da1141878487d22d20 (patch) | |
| tree | 37482f150abf032bbd41eaed553cfd4995bd9da4 | |
| parent | 33c186baf7f06ea7a5e7470b8a441af399d82a56 (diff) | |
| parent | 321fab4337324a66fd79a69ef1bd322062ae374e (diff) | |
| download | rust-de712f9e0af724f513e3b8da1141878487d22d20.tar.gz rust-de712f9e0af724f513e3b8da1141878487d22d20.zip | |
Rollup merge of #136818 - a1phyr:io_repeat_exact, r=jhpratt
Implement `read*_exact` for `std:io::repeat` cc #136756
| -rw-r--r-- | library/std/src/io/util.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs index b4c4dffc371..424f862090f 100644 --- a/library/std/src/io/util.rs +++ b/library/std/src/io/util.rs @@ -188,6 +188,13 @@ impl Read for Repeat { Ok(buf.len()) } + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + for slot in &mut *buf { + *slot = self.byte; + } + Ok(()) + } + fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> io::Result<()> { // SAFETY: No uninit bytes are being written for slot in unsafe { buf.as_mut() } { @@ -204,6 +211,10 @@ impl Read for Repeat { Ok(()) } + fn read_buf_exact(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.read_buf(buf) + } + /// This function is not supported by `io::Repeat`, because there's no end of its data fn read_to_end(&mut self, _: &mut Vec<u8>) -> io::Result<usize> { Err(io::Error::from(io::ErrorKind::OutOfMemory)) |
