File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,19 @@ impl Write for &mut [u8] {
152
152
}
153
153
}
154
154
155
+ #[ cfg( not( feature = "std" ) ) ]
156
+ impl Read for & mut [ u8 ] {
157
+ type Error = EndOfFile ;
158
+
159
+ #[ inline]
160
+ fn read_exact ( & mut self , data : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
161
+ let mut immutable: & [ u8 ] = self ;
162
+ immutable. read_exact ( data) ?;
163
+ * self = & mut core:: mem:: take ( self ) [ data. len ( ) ..] ;
164
+ Ok ( ( ) )
165
+ }
166
+ }
167
+
155
168
#[ cfg( all( not( feature = "std" ) , feature = "alloc" ) ) ]
156
169
impl Write for alloc:: vec:: Vec < u8 > {
157
170
type Error = core:: convert:: Infallible ;
@@ -205,6 +218,20 @@ mod test {
205
218
reader. read_exact ( & mut buffer[ ..] ) . unwrap_err ( ) ;
206
219
}
207
220
221
+ #[ test]
222
+ fn read_mut_two ( ) {
223
+ let mut reader = & mut [ 1u8 ; 2 ] [ ..] ;
224
+ let mut buffer = [ 0u8 ; 1 ] ;
225
+
226
+ reader. read_exact ( & mut buffer[ ..] ) . unwrap ( ) ;
227
+ assert_eq ! ( buffer[ 0 ] , 1 ) ;
228
+
229
+ reader. read_exact ( & mut buffer[ ..] ) . unwrap ( ) ;
230
+ assert_eq ! ( buffer[ 0 ] , 1 ) ;
231
+
232
+ reader. read_exact ( & mut buffer[ ..] ) . unwrap_err ( ) ;
233
+ }
234
+
208
235
#[ test]
209
236
#[ cfg( feature = "std" ) ]
210
237
fn read_std ( ) {
You can’t perform that action at this time.
0 commit comments