@@ -5,9 +5,7 @@ use crate::alloc::Allocator;
5
5
use crate :: cmp;
6
6
use crate :: collections:: VecDeque ;
7
7
use crate :: fmt;
8
- use crate :: io:: {
9
- self , BorrowedCursor , BufRead , ErrorKind , IoSlice , IoSliceMut , Read , Seek , SeekFrom , Write ,
10
- } ;
8
+ use crate :: io:: { self , BorrowedCursor , BufRead , IoSlice , IoSliceMut , Read , Seek , SeekFrom , Write } ;
11
9
use crate :: mem;
12
10
use crate :: str;
13
11
@@ -289,10 +287,7 @@ impl Read for &[u8] {
289
287
#[ inline]
290
288
fn read_exact ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < ( ) > {
291
289
if buf. len ( ) > self . len ( ) {
292
- return Err ( io:: const_io_error!(
293
- ErrorKind :: UnexpectedEof ,
294
- "failed to fill whole buffer"
295
- ) ) ;
290
+ return Err ( io:: Error :: READ_EXACT_EOF ) ;
296
291
}
297
292
let ( a, b) = self . split_at ( buf. len ( ) ) ;
298
293
@@ -312,10 +307,7 @@ impl Read for &[u8] {
312
307
#[ inline]
313
308
fn read_buf_exact ( & mut self , mut cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
314
309
if cursor. capacity ( ) > self . len ( ) {
315
- return Err ( io:: const_io_error!(
316
- ErrorKind :: UnexpectedEof ,
317
- "failed to fill whole buffer"
318
- ) ) ;
310
+ return Err ( io:: Error :: READ_EXACT_EOF ) ;
319
311
}
320
312
let ( a, b) = self . split_at ( cursor. capacity ( ) ) ;
321
313
@@ -336,9 +328,7 @@ impl Read for &[u8] {
336
328
337
329
#[ inline]
338
330
fn read_to_string ( & mut self , buf : & mut String ) -> io:: Result < usize > {
339
- let content = str:: from_utf8 ( self ) . map_err ( |_| {
340
- io:: const_io_error!( ErrorKind :: InvalidData , "stream did not contain valid UTF-8" )
341
- } ) ?;
331
+ let content = str:: from_utf8 ( self ) . map_err ( |_| io:: Error :: INVALID_UTF8 ) ?;
342
332
buf. push_str ( content) ;
343
333
let len = self . len ( ) ;
344
334
* self = & self [ len..] ;
@@ -399,11 +389,7 @@ impl Write for &mut [u8] {
399
389
400
390
#[ inline]
401
391
fn write_all ( & mut self , data : & [ u8 ] ) -> io:: Result < ( ) > {
402
- if self . write ( data) ? == data. len ( ) {
403
- Ok ( ( ) )
404
- } else {
405
- Err ( io:: const_io_error!( ErrorKind :: WriteZero , "failed to write whole buffer" ) )
406
- }
392
+ if self . write ( data) ? == data. len ( ) { Ok ( ( ) ) } else { Err ( io:: Error :: WRITE_ALL_EOF ) }
407
393
}
408
394
409
395
#[ inline]
@@ -491,9 +477,7 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
491
477
// middle of an UTF-8 character.
492
478
let len = self . len ( ) ;
493
479
let content = self . make_contiguous ( ) ;
494
- let string = str:: from_utf8 ( content) . map_err ( |_| {
495
- io:: const_io_error!( ErrorKind :: InvalidData , "stream did not contain valid UTF-8" )
496
- } ) ?;
480
+ let string = str:: from_utf8 ( content) . map_err ( |_| io:: Error :: INVALID_UTF8 ) ?;
497
481
buf. push_str ( string) ;
498
482
self . clear ( ) ;
499
483
Ok ( len)
0 commit comments