Skip to content
/ rust Public
forked from rust-lang/rust

Commit bd49a4b

Browse files
committed
Implement optional methods for unsupported stdio
Match what `std::io::Empty` does, since it is very similar. However, still evaluate the `fmt::Arguments` in `write_fmt` to be consistent with other platforms.
1 parent 60805dc commit bd49a4b

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

library/std/src/sys/stdio/unsupported.rs

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::io;
1+
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
22

33
pub struct Stdin;
44
pub struct Stdout;
@@ -11,9 +11,47 @@ impl Stdin {
1111
}
1212

1313
impl io::Read for Stdin {
14+
#[inline]
1415
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
1516
Ok(0)
1617
}
18+
19+
#[inline]
20+
fn read_buf(&mut self, _cursor: BorrowedCursor<'_>) -> io::Result<()> {
21+
Ok(())
22+
}
23+
24+
#[inline]
25+
fn read_vectored(&mut self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
26+
Ok(0)
27+
}
28+
29+
#[inline]
30+
fn is_read_vectored(&self) -> bool {
31+
// Do not force `Chain<Empty, T>` or `Chain<T, Empty>` to use vectored
32+
// reads, unless the other reader is vectored.
33+
false
34+
}
35+
36+
#[inline]
37+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
38+
if !buf.is_empty() { Err(io::Error::READ_EXACT_EOF) } else { Ok(()) }
39+
}
40+
41+
#[inline]
42+
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
43+
if cursor.capacity() != 0 { Err(io::Error::READ_EXACT_EOF) } else { Ok(()) }
44+
}
45+
46+
#[inline]
47+
fn read_to_end(&mut self, _buf: &mut Vec<u8>) -> io::Result<usize> {
48+
Ok(0)
49+
}
50+
51+
#[inline]
52+
fn read_to_string(&mut self, _buf: &mut String) -> io::Result<usize> {
53+
Ok(0)
54+
}
1755
}
1856

1957
impl Stdout {
@@ -23,10 +61,35 @@ impl Stdout {
2361
}
2462

2563
impl io::Write for Stdout {
64+
#[inline]
2665
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
2766
Ok(buf.len())
2867
}
2968

69+
#[inline]
70+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
71+
let total_len = bufs.iter().map(|b| b.len()).sum();
72+
Ok(total_len)
73+
}
74+
75+
#[inline]
76+
fn is_write_vectored(&self) -> bool {
77+
true
78+
}
79+
80+
#[inline]
81+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
82+
Ok(())
83+
}
84+
85+
#[inline]
86+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
87+
Ok(())
88+
}
89+
90+
// Keep the default write_fmt so the `fmt::Arguments` are still evaluated.
91+
92+
#[inline]
3093
fn flush(&mut self) -> io::Result<()> {
3194
Ok(())
3295
}

0 commit comments

Comments
 (0)