@@ -12,27 +12,47 @@ use core::prelude::*;
1212
1313use boxed:: Box ;
1414use cmp;
15- use io:: { self , SeekFrom , Read , Write , Seek , BufRead } ;
15+ use io:: { self , SeekFrom , Read , Write , Seek , BufRead , Error , ErrorKind } ;
16+ use fmt;
1617use mem;
1718use slice;
19+ use string:: String ;
1820use vec:: Vec ;
1921
2022// =============================================================================
2123// Forwarding implementations
2224
2325impl < ' a , R : Read + ?Sized > Read for & ' a mut R {
2426 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > { ( * * self ) . read ( buf) }
27+
28+ fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > { ( * * self ) . read_to_end ( buf) }
29+
30+ fn read_to_string ( & mut self , buf : & mut String ) -> io:: Result < ( ) > {
31+ ( * * self ) . read_to_string ( buf)
32+ }
2533}
2634impl < ' a , W : Write + ?Sized > Write for & ' a mut W {
2735 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > { ( * * self ) . write ( buf) }
36+
37+ fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > { ( * * self ) . write_all ( buf) }
38+
39+ fn write_fmt ( & mut self , fmt : fmt:: Arguments ) -> io:: Result < ( ) > { ( * * self ) . write_fmt ( fmt) }
40+
2841 fn flush ( & mut self ) -> io:: Result < ( ) > { ( * * self ) . flush ( ) }
2942}
3043impl < ' a , S : Seek + ?Sized > Seek for & ' a mut S {
3144 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > { ( * * self ) . seek ( pos) }
3245}
3346impl < ' a , B : BufRead + ?Sized > BufRead for & ' a mut B {
3447 fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > { ( * * self ) . fill_buf ( ) }
48+
3549 fn consume ( & mut self , amt : usize ) { ( * * self ) . consume ( amt) }
50+
51+ fn read_until ( & mut self , byte : u8 , buf : & mut Vec < u8 > ) -> io:: Result < ( ) > {
52+ ( * * self ) . read_until ( byte, buf)
53+ }
54+
55+ fn read_line ( & mut self , buf : & mut String ) -> io:: Result < ( ) > { ( * * self ) . read_line ( buf) }
3656}
3757
3858impl < R : Read + ?Sized > Read for Box < R > {
@@ -76,6 +96,15 @@ impl<'a> Write for &'a mut [u8] {
7696 * self = b;
7797 Ok ( amt)
7898 }
99+
100+ fn write_all ( & mut self , data : & [ u8 ] ) -> io:: Result < ( ) > {
101+ if try!( self . write ( data) ) == data. len ( ) {
102+ Ok ( ( ) )
103+ } else {
104+ Err ( Error :: new ( ErrorKind :: WriteZero , "failed to write whole buffer" , None ) )
105+ }
106+ }
107+
79108 fn flush ( & mut self ) -> io:: Result < ( ) > { Ok ( ( ) ) }
80109}
81110
@@ -84,5 +113,11 @@ impl Write for Vec<u8> {
84113 self . push_all ( buf) ;
85114 Ok ( buf. len ( ) )
86115 }
116+
117+ fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
118+ try!( self . write ( buf) ) ;
119+ Ok ( ( ) )
120+ }
121+
87122 fn flush ( & mut self ) -> io:: Result < ( ) > { Ok ( ( ) ) }
88123}
0 commit comments