Struct j2ds::RingBuffer[][src]

pub struct RingBuffer<T: Clone> { /* fields omitted */ }

A FIFO buffer with fixed length

Example:

use j2ds::*;

let mut rb = RingBuffer::new(100, 0u8);
rb.push_back(1);
rb.push_back_slice(&[2, 3]);
// ...
let mut buf = [0u8; 3];
rb.pop_front_slice(&mut buf);
assert_eq!(buf, [1, 2, 3]);

Methods

impl<T: Clone> RingBuffer<T>
[src]

Create a new ring buffer that can hold up to size elements and use value as the default value

Add value to the end of the queue. Returns false if there is not enough room in the queue

Remove the first value from the queue, or returns None if there are no values in the buffer

Copy the first value from the queue but does not remove it; returns None if there are no values in the buffer

Add all values to the buffer. If there is not enough room in the queue then no values are added and the return value is false

Remove enough values from the buffer to fill the given slice. If there are not enough values in the queue then the output buffer is not modified and the function returns false

Returns the number of values in the buffer

Returns the number of free slots in the buffer

Returns the max number of values that can ever be stored in the buffer

Auto Trait Implementations

impl<T> Send for RingBuffer<T> where
    T: Send

impl<T> Sync for RingBuffer<T> where
    T: Sync