pub struct CircularBuffer { /* private fields */ }Expand description
A fixed-size circular buffer
buffer: The underlying storage for the circular buffer.max_size: The maximum capacity of the buffer.write_index: The position in the buffer where the next chunk will be written.
Implementations§
Source§impl CircularBuffer
impl CircularBuffer
Sourcepub fn add_chunk(&mut self, chunk: &[f32])
pub fn add_chunk(&mut self, chunk: &[f32])
Adds a chunk of data to the circular buffer.
If the chunk is larger than the buffer size, only the last max_size elements are stored.
If the chunk wraps around the end of the buffer, it is split and written in two parts.
§Arguments
chunk- A slice off32values to add to the buffer.
Sourcepub fn copy_to_buffer(&self, output: &mut [f32])
pub fn copy_to_buffer(&self, output: &mut [f32])
Copies the current state of the circular buffer into an output slice.
The data is copied in order, starting from the oldest data to the newest.
§Arguments
output- A mutable slice where the buffer contents will be copied.
§Panics
Panics if output is not the same length as the circular buffer (max_size).
Sourcepub fn get_buffer(&self) -> Vec<f32>
pub fn get_buffer(&self) -> Vec<f32>
Returns a copy of the current state of the buffer as a vector.
The data is ordered, starting from the oldest to the newest values.
§Returns
A Vec<f32> containing the buffer contents.
Auto Trait Implementations§
impl Freeze for CircularBuffer
impl RefUnwindSafe for CircularBuffer
impl Send for CircularBuffer
impl Sync for CircularBuffer
impl Unpin for CircularBuffer
impl UnwindSafe for CircularBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more