Skip to content

Commit 02020fd

Browse files
jhprattgitbot
authored and
gitbot
committed
Rollup merge of rust-lang#136818 - a1phyr:io_repeat_exact, r=jhpratt
Implement `read*_exact` for `std:io::repeat` cc rust-lang#136756
2 parents 6060897 + 58c91d4 commit 02020fd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

std/src/io/util.rs

+11
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ impl Read for Repeat {
188188
Ok(buf.len())
189189
}
190190

191+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
192+
for slot in &mut *buf {
193+
*slot = self.byte;
194+
}
195+
Ok(())
196+
}
197+
191198
fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
192199
// SAFETY: No uninit bytes are being written
193200
for slot in unsafe { buf.as_mut() } {
@@ -204,6 +211,10 @@ impl Read for Repeat {
204211
Ok(())
205212
}
206213

214+
fn read_buf_exact(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
215+
self.read_buf(buf)
216+
}
217+
207218
/// This function is not supported by `io::Repeat`, because there's no end of its data
208219
fn read_to_end(&mut self, _: &mut Vec<u8>) -> io::Result<usize> {
209220
Err(io::Error::from(io::ErrorKind::OutOfMemory))

0 commit comments

Comments
 (0)