Crate nsrb

Crate nsrb 

Source
Expand description

Nifty Simple Ring Buffer (aka circular buffer) is a no_std crate that provides the ring! and manx! macros to easily create circular buffer data structure on the stack.

§Example

// Import crate with #[macro_use] 
#[macro_use] extern crate nsrb;
 
// Use ring! macro to create circular buffer structure.
nsrb::ring!(pub(crate) ExampleRB[usize; 10]); 
 
// You can implement and access buffer inner variables if needed.
impl ExampleRB {
    pub fn head(&self) -> usize {
        self.head
    }
}
 
fn main() {
    // Use struct in code.
    let mut rb = ExampleRB::new();
    rb.push(5);
    assert_eq!(*rb.pop().unwrap(), 5);
    assert_eq!(rb.head(), 1);   // Using newly implemented method.
}

Macros§

manx
Create a no tail Manx buffer data structure.
ring
Create a ring buffer (aka circular buffer) data structure.

Constants§

NSRB_LOWER_LIMIT
Smallest size a ring buffer can be. Default : 2.
NSRB_UPPER_LIMIT
Largest size a ring buffer can be. Default : u16::MAX.