RingBuffer

Struct RingBuffer 

Source
pub struct RingBuffer<T: DataPoint + Copy, const N: usize> { /* private fields */ }
Expand description

High-performance ring buffer optimized for real-time data

Implementations§

Source§

impl<T: DataPoint + Copy, const N: usize> RingBuffer<T, N>

Source

pub fn new() -> Self

Create a new ring buffer with default configuration

Source

pub fn with_config(config: RingBufferConfig) -> Self

Create a new ring buffer with custom configuration

Source

pub fn set_event_handler(&mut self, handler: fn(RingBufferEvent))

Set event handler for notifications

Source

pub fn push(&mut self, value: T) -> ChartResult<()>

Push a new value into the ring buffer

Source

pub fn extend<I>(&mut self, iter: I) -> ChartResult<usize>
where I: IntoIterator<Item = T>,

Push multiple values efficiently

Source

pub fn pop(&mut self) -> Option<T>

Pop the oldest value from the ring buffer

Source

pub fn peek(&self) -> Option<&T>

Peek at the oldest value without removing it

Source

pub fn peek_newest(&self) -> Option<&T>

Peek at the newest value without removing it

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Get an iterator over all values in the buffer

Source

pub fn iter_chronological(&self) -> ChronologicalIter<'_, T, N>

Get an iterator over all values in chronological order (oldest to newest) This properly handles the wrap-around case when the buffer is full

Source

pub fn recent(&self, n: usize) -> impl Iterator<Item = &T>

Get a slice of the most recent n values

Source

pub fn clear(&mut self)

Clear all data from the buffer

Source

pub fn len(&self) -> usize

Get the number of elements in the buffer

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty

Source

pub fn is_full(&self) -> bool

Check if the buffer is full

Source

pub fn capacity(&self) -> usize

Get the capacity of the buffer

Source

pub fn remaining_capacity(&self) -> usize

Get remaining capacity

Source

pub fn bounds(&self) -> Option<DataBounds<f32, f32>>

Get current bounds (if tracking is enabled and T is Point2D)

Source

pub fn stats(&self) -> &RingBufferStats

Get performance statistics

Source

pub fn reset_stats(&mut self)

Reset performance statistics

Source

pub fn for_each<F>(&self, f: F)
where F: FnMut(&T),

Apply a function to all elements in the buffer

Source

pub fn find<F>(&self, predicate: F) -> Option<&T>
where F: FnMut(&T) -> bool,

Find the first element matching a predicate

Source§

impl<const N: usize> RingBuffer<Point2D, N>

Source

pub fn push_point(&mut self, point: Point2D) -> ChartResult<()>

Push a Point2D with bounds tracking

Source

pub fn moving_average(&self, window_size: usize) -> Option<Point2D>

Calculate moving average over the last n points

Source

pub fn downsample(&self, factor: usize) -> Vec<Point2D, N>

Downsample data by taking every nth point

Source

pub fn rate_of_change(&self) -> Option<f32>

Get the rate of change between the newest and oldest points

Trait Implementations§

Source§

impl<T: DataPoint + Copy, const N: usize> Default for RingBuffer<T, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for RingBuffer<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for RingBuffer<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for RingBuffer<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for RingBuffer<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for RingBuffer<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for RingBuffer<T, N>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.