Struct cbuf::CBuf
[−]
[src]
pub struct CBuf<'a, T: 'a> { /* fields omitted */ }
Circular Buffer
Turns a slice into a Circular buffer with head and tail indexes.
Methods
impl<'a, T: Clone> CBuf<'a, T>
[src]
fn new(buf: &'a mut [T]) -> CBuf<T>
Create new CBuf
Length (not capacity) will be used to store elements in the circular buffer.
panics if buf.len() == 0
fn len(&self) -> usize
get the buffer length
fn as_ptr(&self) -> *const T
Returns an raw pointer to the cbuf's buffer
The caller must ensure that the cbuf outlives the pointer this function returns, or else it will end up pointing to garbage.
fn as_mut_ptr(&mut self) -> *mut T
Returns an unsafe mutable pointer to the cbuf's buffer.
The caller must ensure that the cbuf outlives the pointer this function returns, or else it will end up pointing to garbage.
fn is_full(&self) -> bool
Is buffer full?
fn is_empty(&self) -> bool
Is buffer empty?
fn peek(&mut self) -> Option<&T>
Peek next element from the CBuf without removing it
Returns None
if buffer is empty.
unsafe fn peek_unchecked(&mut self) -> &T
Peek next element from the CBuf without removing it
unsafe: if the buffer is empty, undefined data will be returned.
fn get(&mut self) -> Option<T>
Remove one element from the CBuf
Returns None
if buffer is empty.
unsafe fn get_unchecked(&mut self) -> T
Remove one element from the CBuf
unsafe: Makes the buffer misbehave if it's empty.
fn put(&mut self, val: T)
Add element the buffer
Ignores the write if buffer is full.
unsafe fn put_unchecked(&mut self, val: T)
Add element the buffer
unsafe: Makes the buffer misbehave if it's full.