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]
impl<T: Clone> RingBuffer<T>
pub fn new(size: usize, value: T) -> RingBuffer<T>
[src]
pub fn new(size: usize, value: T) -> RingBuffer<T>
Create a new ring buffer that can hold up to size
elements
and use value
as the default value
pub fn push_back(&mut self, value: T) -> bool
[src]
pub fn push_back(&mut self, value: T) -> bool
Add value
to the end of the queue. Returns false if there is
not enough room in the queue
pub fn pop_front(&mut self) -> Option<T>
[src]
pub fn pop_front(&mut self) -> Option<T>
Remove the first value from the queue, or returns None
if
there are no values in the buffer
pub fn peek_front(&self) -> Option<T>
[src]
pub fn peek_front(&self) -> Option<T>
Copy the first value from the queue but does not remove it;
returns None
if there are no values in the buffer
pub fn push_back_slice(&mut self, values: &[T]) -> bool
[src]
pub fn push_back_slice(&mut self, values: &[T]) -> bool
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
pub fn pop_front_slice(&mut self, values: &mut [T]) -> bool
[src]
pub fn pop_front_slice(&mut self, values: &mut [T]) -> bool
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
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number of values in the buffer
pub fn capacity(&self) -> usize
[src]
pub fn capacity(&self) -> usize
Returns the number of free slots in the buffer
pub fn max_len(&self) -> usize
[src]
pub fn max_len(&self) -> usize
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> Send for RingBuffer<T> where
T: Send,
impl<T> Sync for RingBuffer<T> where
T: Sync,
impl<T> Sync for RingBuffer<T> where
T: Sync,