Skip to content

Commit 902a9dc

Browse files
committed
Add Read Impl for &Stdin
1 parent 0250ef2 commit 902a9dc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

library/std/src/io/stdio.rs

+23
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,29 @@ impl Read for Stdin {
445445
}
446446
}
447447

448+
#[stable(feature = "rust1", since = "1.0.0")]
449+
impl Read for &Stdin {
450+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
451+
self.lock().read(buf)
452+
}
453+
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
454+
self.lock().read_vectored(bufs)
455+
}
456+
#[inline]
457+
fn is_read_vectored(&self) -> bool {
458+
self.lock().is_read_vectored()
459+
}
460+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
461+
self.lock().read_to_end(buf)
462+
}
463+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
464+
self.lock().read_to_string(buf)
465+
}
466+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
467+
self.lock().read_exact(buf)
468+
}
469+
}
470+
448471
// only used by platform-dependent io::copy specializations, i.e. unused on some platforms
449472
#[cfg(any(target_os = "linux", target_os = "android"))]
450473
impl StdinLock<'_> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
use std::io::{self, Read};
3+
4+
fn main() {
5+
let x = io::stdin();
6+
foo(&x);
7+
}
8+
9+
fn foo<T: Read>(t: T) {}

0 commit comments

Comments
 (0)