1
- use crate :: io;
1
+ use crate :: io:: { self , BorrowedCursor , IoSlice , IoSliceMut } ;
2
2
3
3
pub struct Stdin ;
4
4
pub struct Stdout ;
@@ -11,9 +11,47 @@ impl Stdin {
11
11
}
12
12
13
13
impl io:: Read for Stdin {
14
+ #[ inline]
14
15
fn read ( & mut self , _buf : & mut [ u8 ] ) -> io:: Result < usize > {
15
16
Ok ( 0 )
16
17
}
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
+ }
17
55
}
18
56
19
57
impl Stdout {
@@ -23,10 +61,35 @@ impl Stdout {
23
61
}
24
62
25
63
impl io:: Write for Stdout {
64
+ #[ inline]
26
65
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
27
66
Ok ( buf. len ( ) )
28
67
}
29
68
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]
30
93
fn flush ( & mut self ) -> io:: Result < ( ) > {
31
94
Ok ( ( ) )
32
95
}
0 commit comments