Skip to content

Commit

Permalink
Rollup merge of #136818 - a1phyr:io_repeat_exact, r=jhpratt
Browse files Browse the repository at this point in the history
Implement `read*_exact` for `std:io::repeat`

cc #136756
  • Loading branch information
jhpratt authored Feb 13, 2025
2 parents 33c186b + 321fab4 commit de712f9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions library/std/src/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() } {
Expand All @@ -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))
Expand Down

0 comments on commit de712f9

Please sign in to comment.