Crate bndpresbufq

Crate bndpresbufq 

Source
Expand description

BndPresLimBufQ is a bounds-preserving, optionally limited, buffer queue.

§Terminology

length is used to refer the number of elements in the queue. size is used to refer to the total amount of bytes in the queue.

§Example

use bndpresbufq::BndPresLimBufQ;

// Construct a queue with a maximum 2 element length limit and 4 bytes size
// limit
let mut q = BndPresLimBufQ::new(Some(2), Some(4));

// Add elements to fill up to queue
q.try_push(vec![1, 2]).unwrap();
q.force_push(vec![3, 4]);

// Fail to add new node
assert_eq!(q.try_push(vec![5]), Err(vec![5]));

// Forcibly add node; expelling the oldest node
q.force_push([6].into());

assert_eq!(q.pop(), Some(vec![3, 4]));
assert_eq!(q.pop(), Some(vec![6]));
assert_eq!(q.pop(), None);

Structs§

BndPresLimBufQ
A bounds-preserving, optionally limited, buffer queue.