Add consume_noshift (consume data without moving it)
This commit is contained in:
parent
3f4a7b6c86
commit
0b80624939
18
src/lib.rs
18
src/lib.rs
|
@ -140,6 +140,16 @@ impl Buffer {
|
||||||
cnt
|
cnt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// advances the position tracker
|
||||||
|
///
|
||||||
|
/// This method is similar to `consume()` but will not move data
|
||||||
|
/// to the beginning of the buffer
|
||||||
|
pub fn consume_noshift(&mut self, count: usize) -> usize {
|
||||||
|
let cnt = cmp::min(count, self.available_data());
|
||||||
|
self.position += cnt;
|
||||||
|
cnt
|
||||||
|
}
|
||||||
|
|
||||||
/// after having written data to the buffer, use this function
|
/// after having written data to the buffer, use this function
|
||||||
/// to indicate how many bytes were written
|
/// to indicate how many bytes were written
|
||||||
///
|
///
|
||||||
|
@ -394,4 +404,12 @@ mod tests {
|
||||||
assert_eq!(b.available_data(), 3);
|
assert_eq!(b.available_data(), 3);
|
||||||
println!("{:?}", b.position());
|
println!("{:?}", b.position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn consume_without_shift() {
|
||||||
|
let mut b = Buffer::with_capacity(10);
|
||||||
|
let _ = b.write(&b"abcdefgh"[..]);
|
||||||
|
b.consume_noshift(6);
|
||||||
|
assert_eq!(b.position(), 6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue