Skip to content

Commit

Permalink
Add Read Impl for &Stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
Dajamante committed Jul 11, 2022
1 parent c461f7a commit 764fdcd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,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<usize> {
self.lock().read(buf)
}
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
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<u8>) -> io::Result<usize> {
self.lock().read_to_end(buf)
}
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
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<'_> {
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/stdlib-unit-tests/issue-95622.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// check-pass
use std::io::{self, Read};

fn main() {
let x = io::stdin();
foo(&x);
}

fn foo<T: Read>(t: T) {}

0 comments on commit 764fdcd

Please sign in to comment.