about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBenoît du Garreau <bdgdlm@outlook.com>2025-02-10 13:43:12 +0100
committerBenoît du Garreau <bdgdlm@outlook.com>2025-02-10 13:43:12 +0100
commit321fab4337324a66fd79a69ef1bd322062ae374e (patch)
treec98459f23368a0000b8e93e852cb4edc3cf3a6b9
parent80c091958f05e573433df974f8d2f2bc3a3eadfb (diff)
downloadrust-321fab4337324a66fd79a69ef1bd322062ae374e.tar.gz
rust-321fab4337324a66fd79a69ef1bd322062ae374e.zip
Implement `read*_exact` for `std:io::repeat`
cc #136756
-rw-r--r--library/std/src/io/util.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs
index b4c4dffc371..424f862090f 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<u8>) -> io::Result<usize> {
         Err(io::Error::from(io::ErrorKind::OutOfMemory))