@@ -192,67 +192,43 @@ impl<T> Cursor<T> {
192
192
pub fn set_position ( & mut self , pos : u64 ) { self . pos = pos; }
193
193
}
194
194
195
- macro_rules! seek {
196
- ( ) => {
197
- fn seek( & mut self , style: SeekFrom ) -> io:: Result <u64 > {
198
- let pos = match style {
199
- SeekFrom :: Start ( n) => { self . pos = n; return Ok ( n) }
200
- SeekFrom :: End ( n) => self . inner. len( ) as i64 + n,
201
- SeekFrom :: Current ( n) => self . pos as i64 + n,
202
- } ;
203
-
204
- if pos < 0 {
205
- Err ( Error :: new( ErrorKind :: InvalidInput ,
206
- "invalid seek to a negative position" ) )
207
- } else {
208
- self . pos = pos as u64 ;
209
- Ok ( self . pos)
210
- }
195
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
196
+ impl < T > io:: Seek for Cursor < T > where T : AsRef < [ u8 ] > {
197
+ fn seek ( & mut self , style : SeekFrom ) -> io:: Result < u64 > {
198
+ let pos = match style {
199
+ SeekFrom :: Start ( n) => { self . pos = n; return Ok ( n) }
200
+ SeekFrom :: End ( n) => self . inner . as_ref ( ) . len ( ) as i64 + n,
201
+ SeekFrom :: Current ( n) => self . pos as i64 + n,
202
+ } ;
203
+
204
+ if pos < 0 {
205
+ Err ( Error :: new ( ErrorKind :: InvalidInput ,
206
+ "invalid seek to a negative position" ) )
207
+ } else {
208
+ self . pos = pos as u64 ;
209
+ Ok ( self . pos )
211
210
}
212
211
}
213
212
}
214
213
215
214
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
216
- impl < ' a > io:: Seek for Cursor < & ' a [ u8 ] > { seek ! ( ) ; }
217
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
218
- impl < ' a > io:: Seek for Cursor < & ' a mut [ u8 ] > { seek ! ( ) ; }
219
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
220
- impl io:: Seek for Cursor < Vec < u8 > > { seek ! ( ) ; }
221
-
222
- macro_rules! read {
223
- ( ) => {
224
- fn read( & mut self , buf: & mut [ u8 ] ) -> io:: Result <usize > {
225
- let n = try!( Read :: read( & mut try!( self . fill_buf( ) ) , buf) ) ;
226
- self . pos += n as u64 ;
227
- Ok ( n)
228
- }
215
+ impl < T > Read for Cursor < T > where T : AsRef < [ u8 ] > {
216
+ fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
217
+ let n = try!( Read :: read ( & mut try!( self . fill_buf ( ) ) , buf) ) ;
218
+ self . pos += n as u64 ;
219
+ Ok ( n)
229
220
}
230
221
}
231
222
232
223
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
233
- impl < ' a > Read for Cursor < & ' a [ u8 ] > { read ! ( ) ; }
234
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
235
- impl < ' a > Read for Cursor < & ' a mut [ u8 ] > { read ! ( ) ; }
236
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
237
- impl Read for Cursor < Vec < u8 > > { read ! ( ) ; }
238
-
239
- macro_rules! buffer {
240
- ( ) => {
241
- fn fill_buf( & mut self ) -> io:: Result <& [ u8 ] > {
242
- let amt = cmp:: min( self . pos, self . inner. len( ) as u64 ) ;
243
- Ok ( & self . inner[ ( amt as usize ) ..] )
244
- }
245
- fn consume( & mut self , amt: usize ) { self . pos += amt as u64 ; }
224
+ impl < T > BufRead for Cursor < T > where T : AsRef < [ u8 ] > {
225
+ fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > {
226
+ let amt = cmp:: min ( self . pos , self . inner . as_ref ( ) . len ( ) as u64 ) ;
227
+ Ok ( & self . inner . as_ref ( ) [ ( amt as usize ) ..] )
246
228
}
229
+ fn consume ( & mut self , amt : usize ) { self . pos += amt as u64 ; }
247
230
}
248
231
249
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
250
- impl < ' a > BufRead for Cursor < & ' a [ u8 ] > { buffer ! ( ) ; }
251
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
252
- impl < ' a > BufRead for Cursor < & ' a mut [ u8 ] > { buffer ! ( ) ; }
253
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
254
- impl < ' a > BufRead for Cursor < Vec < u8 > > { buffer ! ( ) ; }
255
-
256
232
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
257
233
impl < ' a > Write for Cursor < & ' a mut [ u8 ] > {
258
234
fn write ( & mut self , data : & [ u8 ] ) -> io:: Result < usize > {
0 commit comments