Implement read*_exact for std:io::repeat

cc #136756
This commit is contained in:
Benoît du Garreau 2025-02-10 13:43:12 +01:00
parent 80c091958f
commit 321fab4337

View file

@ -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))