[−][src]Struct ringbuffer::RingBuffer
The RingBuffer struct.
Example
use ringbuffer::RingBuffer; let mut buffer = RingBuffer::with_capacity(2); // First entry of the buffer is now 5. buffer.push(5); assert_eq!(buffer[0], 5); // Second entry is now 42. buffer.push(42); // Because capacity is reached the next push will be the first item of the buffer. buffer.push(1); assert_eq!(buffer[0], 1);
Methods
impl<T> RingBuffer<T>
[src]
pub fn with_capacity(cap: usize) -> Self
[src]
Creates a RingBuffer with a certain capacity.
pub fn new() -> Self
[src]
Creates a RingBuffer with a capacity of RINGBUFFER_DEFAULT_CAPACITY.
pub fn len(&self) -> usize
[src]
Returns the length of the internal buffer.
pub fn is_empty(&self) -> bool
[src]
Returns true if the buffer is empty, some value between 0 and capacity.
pub fn clear(&mut self)
[src]
Empties the buffer.
pub fn capacity(&self) -> usize
[src]
Returns the capacity of the buffer.
pub fn push(&mut self, e: T)
[src]
Pushes a value onto the buffer. Cycles around if capacity is reached.
pub fn peek(&self) -> Option<&T>
[src]
Returns the value at the current index. This is the value that will be overwritten by the next push.
pub fn iter(&self) -> Iter<T>
[src]
Creates an iterator over the buffer starting from the latest push.
pub fn iter_mut(&mut self) -> IterMut<T>
[src]
Creates a mutable iterator over the buffer starting from the latest push.
pub fn to_vec(&self) -> Vec<T> where
T: Copy,
[src]
T: Copy,
Converts the buffer to an vector.
Trait Implementations
impl<T: Debug> Debug for RingBuffer<T>
[src]
impl<T> Default for RingBuffer<T>
[src]
fn default() -> Self
[src]
Creates a buffer with a capacity of RINGBUFFER_DEFAULT_CAPACITY.
impl<T> Index<usize> for RingBuffer<T>
[src]
type Output = T
The returned type after indexing.
fn index(&self, index: usize) -> &Self::Output
[src]
impl<T> IndexMut<usize> for RingBuffer<T>
[src]
impl<T: PartialEq> PartialEq<RingBuffer<T>> for RingBuffer<T>
[src]
fn eq(&self, other: &RingBuffer<T>) -> bool
[src]
fn ne(&self, other: &RingBuffer<T>) -> bool
[src]
impl<T> StructuralPartialEq for RingBuffer<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for RingBuffer<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for RingBuffer<T> where
T: Send,
T: Send,
impl<T> Sync for RingBuffer<T> where
T: Sync,
T: Sync,
impl<T> Unpin for RingBuffer<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for RingBuffer<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,