Skip to content

Commit 0b80624

Browse files
committed
Add consume_noshift (consume data without moving it)
1 parent 3f4a7b6 commit 0b80624

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ impl Buffer {
140140
cnt
141141
}
142142

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+
143153
/// after having written data to the buffer, use this function
144154
/// to indicate how many bytes were written
145155
///
@@ -394,4 +404,12 @@ mod tests {
394404
assert_eq!(b.available_data(), 3);
395405
println!("{:?}", b.position());
396406
}
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+
}
397415
}

0 commit comments

Comments
 (0)