Expand description
Bounds-preserving, optionally explicitly limited/lossy, buffer channel.
use bndpresbufch::{Builder, Error};
// Create a buffer queue that can hold at most two buffers, with a total of
// 4 bytes of data.
let (tx, rx) = Builder::new()
.max_len(2)
.max_size(4)
.build();
// Fail to push a single buffer that is larger than maximum allowed total
// queue size.
assert_eq!(tx.force_push(vec![1, 2, 3, 4, 5]),
Err(Error::WontFit(vec![1, 2, 3, 4, 5])));
// Fill up queue
tx.try_push(vec![1, 2]).unwrap();
tx.force_push(vec![3, 4]).unwrap();
// Fail to add more data
assert_eq!(tx.try_push(vec![5]), Err(Error::WontFit(vec![5])));
// Force push data to the queue, ejecting the oldest buffer
tx.force_push(vec![6]).unwrap();
assert_eq!(rx.pop(), Some(vec![3, 4]));
assert_eq!(rx.try_pop(), Ok(Some(vec![6])));
assert_eq!(rx.try_pop(), Ok(None));Structs§
- Builder for a bounds-preserving buffer channel.
- Wrapper around elements that must be handled by the application.
- Receiving end-point used to receive bounds-preserved buffers from a
Senderend-point. - Transmitting end-point used to transfer bounds-preserved buffers to a
Receiverend-point.
Enums§
- Crate-specific errors.