Skip to content

Implement read*_exact for std:io::repeat #136818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading