From 321fab4337324a66fd79a69ef1bd322062ae374e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Mon, 10 Feb 2025 13:43:12 +0100 Subject: [PATCH] Implement `read*_exact` for `std:io::repeat` cc #136756 --- library/std/src/io/util.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs index b4c4dffc371c1..424f862090f09 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) -> io::Result { Err(io::Error::from(io::ErrorKind::OutOfMemory))