Skip to main content

Crate ring_pair

Crate ring_pair 

Source
Expand description

Tiny ring-buffer types specialized for exactly two elements.

This crate provides:

  • RingPair, storing values inline as [T; 2]
  • BoxedRingPair, storing values on the heap as Box<[T; 2]> (requires the alloc feature)

§no_std support

This crate is no_std compatible. RingPair is always available. BoxedRingPair requires the alloc feature (enabled by default).

§Examples

use ring_pair::RingPair;

let mut inline = RingPair::new(1);
inline.push(2);
assert_eq!(inline.as_pair(), (&1, &2));
use ring_pair::BoxedRingPair;

let mut boxed = BoxedRingPair::new(String::from("a"));
boxed.push(String::from("b"));
assert_eq!(boxed.as_pair(), (&String::from("a"), &String::from("b")));

Structs§

BoxedRingPair
Circular buffer holding exactly 2 elements with boxed storage and O(1) push.
Iter
Iterator over references to the elements of a ring pair, from oldest to newest.
RingPair
Circular buffer holding exactly 2 elements with O(1) push.