@@ -5,9 +5,7 @@ use crate::alloc::Allocator;
55use crate :: cmp;
66use crate :: collections:: VecDeque ;
77use 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 } ;
119use crate :: mem;
1210use crate :: str;
1311
@@ -289,10 +287,7 @@ impl Read for &[u8] {
289287 #[ inline]
290288 fn read_exact ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < ( ) > {
291289 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 ) ;
296291 }
297292 let ( a, b) = self . split_at ( buf. len ( ) ) ;
298293
@@ -312,10 +307,7 @@ impl Read for &[u8] {
312307 #[ inline]
313308 fn read_buf_exact ( & mut self , mut cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
314309 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 ) ;
319311 }
320312 let ( a, b) = self . split_at ( cursor. capacity ( ) ) ;
321313
@@ -336,9 +328,7 @@ impl Read for &[u8] {
336328
337329 #[ inline]
338330 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 ) ?;
342332 buf. push_str ( content) ;
343333 let len = self . len ( ) ;
344334 * self = & self [ len..] ;
@@ -399,11 +389,7 @@ impl Write for &mut [u8] {
399389
400390 #[ inline]
401391 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 ) }
407393 }
408394
409395 #[ inline]
@@ -491,9 +477,7 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
491477 // middle of an UTF-8 character.
492478 let len = self . len ( ) ;
493479 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 ) ?;
497481 buf. push_str ( string) ;
498482 self . clear ( ) ;
499483 Ok ( len)
0 commit comments