rollbuf

An extendable buffer which rolls the last incomplete part to the beginning so it can be completed and consumed.

Dual-licensed under MIT or unlicense

Documentation

https://docs.rs/rollbuf

Usage

Add this to your Cargo.toml: toml [dependencies] rollbuf = "0.1"

and this to your crate root: rust extern crate rollbuf;

Example

```rust use rollbuf::RollBuf;

let inner: &[u8] = &[1, 2, 3, 4, 5, 6, 7]; let mut b = RollBuf::with_capacity(3, inner);

struct TestCase { consume: usize, roll: bool, want: (Vec, bool), }

let test_cases = vec![ TestCase { consume: 2, roll: false, want: (vec![1, 2, 3], true) }, TestCase { consume: 0, roll: true, want: (vec![1, 2, 3, 4, 5, 6], true) }, TestCase { consume: 4, roll: false, want: (vec![5, 6], true) }, TestCase { consume: 2, roll: true, want: (vec![7], false) }, TestCase { consume: 2, roll: false, want: (vec![], false) }, ];

for t in testcases { b.consume(t.consume); if t.roll { b.roll(); } let isfull = b.fillbuf().unwrap(); let contents = b.contents(); asserteq!((contents, isfull), (t.want.0.asslice(), t.want.1)); } ```