Skip to content
Snippets Groups Projects
Commit a76dd8ed authored by Nandor Kracser's avatar Nandor Kracser Committed by Carl Lerche
Browse files

Add clear method to RingBuf

parent 4ce8b1c2
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,13 @@ impl RingBuf {
}
}
/// Resets all internal state to the initial state.
pub fn clear(&mut self) {
self.pos = 0;
self.len = 0;
self.mark = Mark::NoMark;
}
/// Returns the number of bytes remaining to read.
fn read_remaining(&self) -> usize {
self.len
......
......@@ -120,3 +120,19 @@ fn test_reset_full() {
buf.reset();
assert_eq!(MutBuf::remaining(&buf), 0);
}
#[test]
// Test that "RingBuf::clear" does the full reset
fn test_clear() {
use bytes::traits::{Buf, MutBuf};
use std::io::Write;
let mut buf = RingBuf::new(8);
buf.write(&[0; 8]).unwrap();
assert_eq!(MutBuf::remaining(&buf), 0);
assert_eq!(Buf::remaining(&buf), 8);
buf.clear();
assert_eq!(MutBuf::remaining(&buf), 8);
assert_eq!(Buf::remaining(&buf), 0);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment