Trait RingBuffer
pub trait RingBuffer:
Observer
+ Consumer
+ Producer {
// Required methods
unsafe fn hold_read(&self, flag: bool) -> bool;
unsafe fn hold_write(&self, flag: bool) -> bool;
// Provided methods
fn push_overwrite(&mut self, elem: Self::Item) -> Option<Self::Item> { ... }
fn push_iter_overwrite<I>(&mut self, iter: I)
where I: Iterator<Item = Self::Item> { ... }
fn push_slice_overwrite(&mut self, elems: &[Self::Item])
where Self::Item: Copy { ... }
}
Expand description
An abstract ring buffer that exclusively owns its data.
Required Methods§
unsafe fn hold_read(&self, flag: bool) -> bool
unsafe fn hold_read(&self, flag: bool) -> bool
Tell whether read end of the ring buffer is held by consumer or not.
Returns old value.
§Safety
Must not be set to false
while consumer exists.
unsafe fn hold_write(&self, flag: bool) -> bool
unsafe fn hold_write(&self, flag: bool) -> bool
Tell whether write end of the ring buffer is held by producer or not.
Returns old value.
§Safety
Must not be set to false
while producer exists.
Provided Methods§
fn push_overwrite(&mut self, elem: Self::Item) -> Option<Self::Item>
fn push_overwrite(&mut self, elem: Self::Item) -> Option<Self::Item>
Pushes an item to the ring buffer overwriting the latest item if the buffer is full.
Returns overwritten item if overwriting took place.
fn push_iter_overwrite<I>(&mut self, iter: I)
fn push_iter_overwrite<I>(&mut self, iter: I)
Appends items from an iterator to the ring buffer.
This method consumes iterator until its end.
Exactly last min(iter.len(), capacity)
items from the iterator will be stored in the ring buffer.
fn push_slice_overwrite(&mut self, elems: &[Self::Item])
fn push_slice_overwrite(&mut self, elems: &[Self::Item])
Appends items from slice to the ring buffer overwriting existing items in the ring buffer.
If the slice length is greater than ring buffer capacity then only last capacity
items from slice will be stored in the buffer.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.