From 709ea7469f5093fb488607fcb966445c63d49a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=AFssata?= Date: Mon, 11 Jul 2022 13:12:41 +0000 Subject: [PATCH 1/3] Add Read Impl for &Stdin --- library/std/src/io/stdio.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 261b570dee74f..e929eaa639696 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -445,6 +445,29 @@ impl Read for Stdin { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl Read for &Stdin { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + self.lock().read(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { + self.lock().read_vectored(bufs) + } + #[inline] + fn is_read_vectored(&self) -> bool { + self.lock().is_read_vectored() + } + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + self.lock().read_to_end(buf) + } + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + self.lock().read_to_string(buf) + } + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + self.lock().read_exact(buf) + } +} + // only used by platform-dependent io::copy specializations, i.e. unused on some platforms #[cfg(any(target_os = "linux", target_os = "android"))] impl StdinLock<'_> { From b921a34f1738a615c17db513868b6c5219f32893 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 25 Feb 2024 23:47:10 -0800 Subject: [PATCH 2/3] Fix stable feature name and stabilization version of Read for &Stdin --- library/std/src/io/stdio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index e929eaa639696..6920281f24bf2 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -445,7 +445,7 @@ impl Read for Stdin { } } -#[stable(feature = "rust1", since = "1.0.0")] +#[stable(feature = "read_shared_stdin", since = "CURRENT_RUSTC_VERSION")] impl Read for &Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) From b18280f9d5d07ff1a1b5352924c383c1ed3024e9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 25 Feb 2024 23:50:00 -0800 Subject: [PATCH 3/3] Fill in Read::read_buf for &Stdin --- library/std/src/io/stdio.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 6920281f24bf2..19ed03056a2f9 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -450,6 +450,9 @@ impl Read for &Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.lock().read_buf(buf) + } fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.lock().read_vectored(bufs) }