@@ -12,27 +12,47 @@ use core::prelude::*;
12
12
13
13
use boxed:: Box ;
14
14
use cmp;
15
- use io:: { self , SeekFrom , Read , Write , Seek , BufRead } ;
15
+ use io:: { self , SeekFrom , Read , Write , Seek , BufRead , Error , ErrorKind } ;
16
+ use fmt;
16
17
use mem;
17
18
use slice;
19
+ use string:: String ;
18
20
use vec:: Vec ;
19
21
20
22
// =============================================================================
21
23
// Forwarding implementations
22
24
23
25
impl < ' a , R : Read + ?Sized > Read for & ' a mut R {
24
26
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
+ }
25
33
}
26
34
impl < ' a , W : Write + ?Sized > Write for & ' a mut W {
27
35
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
+
28
41
fn flush ( & mut self ) -> io:: Result < ( ) > { ( * * self ) . flush ( ) }
29
42
}
30
43
impl < ' a , S : Seek + ?Sized > Seek for & ' a mut S {
31
44
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > { ( * * self ) . seek ( pos) }
32
45
}
33
46
impl < ' a , B : BufRead + ?Sized > BufRead for & ' a mut B {
34
47
fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > { ( * * self ) . fill_buf ( ) }
48
+
35
49
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) }
36
56
}
37
57
38
58
impl < R : Read + ?Sized > Read for Box < R > {
@@ -76,6 +96,15 @@ impl<'a> Write for &'a mut [u8] {
76
96
* self = b;
77
97
Ok ( amt)
78
98
}
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
+
79
108
fn flush ( & mut self ) -> io:: Result < ( ) > { Ok ( ( ) ) }
80
109
}
81
110
@@ -84,5 +113,11 @@ impl Write for Vec<u8> {
84
113
self . push_all ( buf) ;
85
114
Ok ( buf. len ( ) )
86
115
}
116
+
117
+ fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
118
+ try!( self . write ( buf) ) ;
119
+ Ok ( ( ) )
120
+ }
121
+
87
122
fn flush ( & mut self ) -> io:: Result < ( ) > { Ok ( ( ) ) }
88
123
}
0 commit comments