Ring

Struct Ring 

Source
pub struct Ring<T, const N: usize> { /* private fields */ }
Expand description

Append only data structure, replace oldest element when reach maximum capacity of N elements

Implementations§

Source§

impl<T: Copy + Default + PartialOrd + Sub<Output = T> + Add<Output = T> + Mul<Output = T> + Div<Output = T> + Into<f32>, const N: usize> Ring<T, N>

Source

pub fn avg(&self) -> f32

Calculate the average of the elements in the Ring

Source

pub fn var(&self, avg: Option<f32>) -> f32

Calculate the variance of the elements in the Ring, use provided avg if Some, otherwise it calculates it (in the latter case two iterations are required).

Source§

impl<T: Copy + Default + PartialOrd + Sub<Output = T> + Add<Output = T> + Mul<Output = T> + Div<Output = T> + Into<f64>, const N: usize> Ring<T, N>

Source

pub fn rescaled_iter( &self, current: Range<T>, desired: Range<T>, ) -> RescaleIterator<'_, T, N>

Returns an iterator over the Ring on which values are rescaled according to the desired range

Source§

impl<T: Copy + Default, const N: usize> Ring<T, N>

Source

pub fn new() -> Self

Creates a new Ring of give size N

Source

pub fn append(&mut self, el: T)

Append an element to the Ring, if there are already N elements, it replaces the oldest.

Source

pub fn len(&self) -> usize

Number of elements in the Ring, it never decreases.

Source

pub fn is_empty(&self) -> bool

If the Ring is empty. Zero elements

Source

pub fn size(&self) -> usize

Return the max size of the ring

Source

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

Return the last item inserted

Source

pub fn iter(&self) -> RingIterator<'_, T, N>

Returns an iterator over the Ring starting from the oldest appended element

Trait Implementations§

Source§

impl<T: Clone, const N: usize> Clone for Ring<T, N>

Source§

fn clone(&self) -> Ring<T, N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const N: usize> Debug for Ring<T, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

fn default() -> Self

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

impl<T: PartialOrd + Copy + Default, const N: usize> FindRange<T> for Ring<T, N>

Source§

fn range(&self) -> Option<Range<T>>

calculate min and max with one iteration

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T, const N: usize> UnwindSafe for Ring<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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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, 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.