File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,16 @@ impl Buffer {
140
140
cnt
141
141
}
142
142
143
+ /// advances the position tracker
144
+ ///
145
+ /// This method is similar to `consume()` but will not move data
146
+ /// to the beginning of the buffer
147
+ pub fn consume_noshift ( & mut self , count : usize ) -> usize {
148
+ let cnt = cmp:: min ( count, self . available_data ( ) ) ;
149
+ self . position += cnt;
150
+ cnt
151
+ }
152
+
143
153
/// after having written data to the buffer, use this function
144
154
/// to indicate how many bytes were written
145
155
///
@@ -394,4 +404,12 @@ mod tests {
394
404
assert_eq ! ( b. available_data( ) , 3 ) ;
395
405
println ! ( "{:?}" , b. position( ) ) ;
396
406
}
407
+
408
+ #[ test]
409
+ fn consume_without_shift ( ) {
410
+ let mut b = Buffer :: with_capacity ( 10 ) ;
411
+ let _ = b. write ( & b"abcdefgh" [ ..] ) ;
412
+ b. consume_noshift ( 6 ) ;
413
+ assert_eq ! ( b. position( ) , 6 ) ;
414
+ }
397
415
}
You can’t perform that action at this time.
0 commit comments