@@ -97,39 +97,53 @@ const fn stderr_raw() -> StderrRaw {
97
97
98
98
impl Read for StdinRaw {
99
99
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
100
- handle_ebadf ( self . 0 . read ( buf) , 0 )
100
+ handle_ebadf ( self . 0 . read ( buf) , || Ok ( 0 ) )
101
101
}
102
102
103
103
fn read_buf ( & mut self , buf : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
104
- handle_ebadf ( self . 0 . read_buf ( buf) , ( ) )
104
+ handle_ebadf ( self . 0 . read_buf ( buf) , || Ok ( ( ) ) )
105
105
}
106
106
107
107
fn read_vectored ( & mut self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
108
- handle_ebadf ( self . 0 . read_vectored ( bufs) , 0 )
108
+ handle_ebadf ( self . 0 . read_vectored ( bufs) , || Ok ( 0 ) )
109
109
}
110
110
111
111
#[ inline]
112
112
fn is_read_vectored ( & self ) -> bool {
113
113
self . 0 . is_read_vectored ( )
114
114
}
115
115
116
+ fn read_exact ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < ( ) > {
117
+ if buf. is_empty ( ) {
118
+ return Ok ( ( ) ) ;
119
+ }
120
+ handle_ebadf ( self . 0 . read_exact ( buf) , || Err ( io:: Error :: READ_EXACT_EOF ) )
121
+ }
122
+
123
+ fn read_buf_exact ( & mut self , buf : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
124
+ if buf. capacity ( ) == 0 {
125
+ return Ok ( ( ) ) ;
126
+ }
127
+ handle_ebadf ( self . 0 . read_buf_exact ( buf) , || Err ( io:: Error :: READ_EXACT_EOF ) )
128
+ }
129
+
116
130
fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
117
- handle_ebadf ( self . 0 . read_to_end ( buf) , 0 )
131
+ handle_ebadf ( self . 0 . read_to_end ( buf) , || Ok ( 0 ) )
118
132
}
119
133
120
134
fn read_to_string ( & mut self , buf : & mut String ) -> io:: Result < usize > {
121
- handle_ebadf ( self . 0 . read_to_string ( buf) , 0 )
135
+ handle_ebadf ( self . 0 . read_to_string ( buf) , || Ok ( 0 ) )
122
136
}
123
137
}
124
138
125
139
impl Write for StdoutRaw {
126
140
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
127
- handle_ebadf ( self . 0 . write ( buf) , buf. len ( ) )
141
+ handle_ebadf ( self . 0 . write ( buf) , || Ok ( buf. len ( ) ) )
128
142
}
129
143
130
144
fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
131
- let total = || bufs. iter ( ) . map ( |b| b. len ( ) ) . sum ( ) ;
132
- handle_ebadf_lazy ( self . 0 . write_vectored ( bufs) , total)
145
+ let total = || Ok ( bufs. iter ( ) . map ( |b| b. len ( ) ) . sum ( ) ) ;
146
+ handle_ebadf ( self . 0 . write_vectored ( bufs) , total)
133
147
}
134
148
135
149
#[ inline]
@@ -138,30 +152,30 @@ impl Write for StdoutRaw {
138
152
}
139
153
140
154
fn flush ( & mut self ) -> io:: Result < ( ) > {
141
- handle_ebadf ( self . 0 . flush ( ) , ( ) )
155
+ handle_ebadf ( self . 0 . flush ( ) , || Ok ( ( ) ) )
142
156
}
143
157
144
158
fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
145
- handle_ebadf ( self . 0 . write_all ( buf) , ( ) )
159
+ handle_ebadf ( self . 0 . write_all ( buf) , || Ok ( ( ) ) )
146
160
}
147
161
148
162
fn write_all_vectored ( & mut self , bufs : & mut [ IoSlice < ' _ > ] ) -> io:: Result < ( ) > {
149
- handle_ebadf ( self . 0 . write_all_vectored ( bufs) , ( ) )
163
+ handle_ebadf ( self . 0 . write_all_vectored ( bufs) , || Ok ( ( ) ) )
150
164
}
151
165
152
166
fn write_fmt ( & mut self , fmt : fmt:: Arguments < ' _ > ) -> io:: Result < ( ) > {
153
- handle_ebadf ( self . 0 . write_fmt ( fmt) , ( ) )
167
+ handle_ebadf ( self . 0 . write_fmt ( fmt) , || Ok ( ( ) ) )
154
168
}
155
169
}
156
170
157
171
impl Write for StderrRaw {
158
172
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
159
- handle_ebadf ( self . 0 . write ( buf) , buf. len ( ) )
173
+ handle_ebadf ( self . 0 . write ( buf) , || Ok ( buf. len ( ) ) )
160
174
}
161
175
162
176
fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
163
- let total = || bufs. iter ( ) . map ( |b| b. len ( ) ) . sum ( ) ;
164
- handle_ebadf_lazy ( self . 0 . write_vectored ( bufs) , total)
177
+ let total = || Ok ( bufs. iter ( ) . map ( |b| b. len ( ) ) . sum ( ) ) ;
178
+ handle_ebadf ( self . 0 . write_vectored ( bufs) , total)
165
179
}
166
180
167
181
#[ inline]
@@ -170,32 +184,25 @@ impl Write for StderrRaw {
170
184
}
171
185
172
186
fn flush ( & mut self ) -> io:: Result < ( ) > {
173
- handle_ebadf ( self . 0 . flush ( ) , ( ) )
187
+ handle_ebadf ( self . 0 . flush ( ) , || Ok ( ( ) ) )
174
188
}
175
189
176
190
fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
177
- handle_ebadf ( self . 0 . write_all ( buf) , ( ) )
191
+ handle_ebadf ( self . 0 . write_all ( buf) , || Ok ( ( ) ) )
178
192
}
179
193
180
194
fn write_all_vectored ( & mut self , bufs : & mut [ IoSlice < ' _ > ] ) -> io:: Result < ( ) > {
181
- handle_ebadf ( self . 0 . write_all_vectored ( bufs) , ( ) )
195
+ handle_ebadf ( self . 0 . write_all_vectored ( bufs) , || Ok ( ( ) ) )
182
196
}
183
197
184
198
fn write_fmt ( & mut self , fmt : fmt:: Arguments < ' _ > ) -> io:: Result < ( ) > {
185
- handle_ebadf ( self . 0 . write_fmt ( fmt) , ( ) )
186
- }
187
- }
188
-
189
- fn handle_ebadf < T > ( r : io:: Result < T > , default : T ) -> io:: Result < T > {
190
- match r {
191
- Err ( ref e) if stdio:: is_ebadf ( e) => Ok ( default) ,
192
- r => r,
199
+ handle_ebadf ( self . 0 . write_fmt ( fmt) , || Ok ( ( ) ) )
193
200
}
194
201
}
195
202
196
- fn handle_ebadf_lazy < T > ( r : io:: Result < T > , default : impl FnOnce ( ) -> T ) -> io:: Result < T > {
203
+ fn handle_ebadf < T > ( r : io:: Result < T > , default : impl FnOnce ( ) -> io :: Result < T > ) -> io:: Result < T > {
197
204
match r {
198
- Err ( ref e) if stdio:: is_ebadf ( e) => Ok ( default ( ) ) ,
205
+ Err ( ref e) if stdio:: is_ebadf ( e) => default ( ) ,
199
206
r => r,
200
207
}
201
208
}
0 commit comments