Struct SlidingWindow

Source
pub struct SlidingWindow<IT, N>
where N: Size<IT>,
{ /* private fields */ }
Expand description

A sliding window.

Sliding windows are queues that overwrite their oldest data when full.

Implementations§

Source§

impl<IT, N> SlidingWindow<IT, N>
where N: Size<IT>,

Source

pub fn new() -> Self

Returns an empty sliding window object.

Source

pub fn insert(&mut self, t: IT) -> Option<IT>

Insert an element into the window.

If the window is full, this method will remove and return the oldest element.

Source

pub fn clear(&mut self)

Removes all elements from the window.

Source

pub fn is_full(&self) -> bool

Returns true if the window is full.

Source

pub fn count(&self) -> usize

Returns the number of elements stored in the window.

Source

pub fn iter(&self) -> Iter<'_, IT, N>

Returns an iterator to read from the window.

The iterator starts at the oldest element and ends with the newest.

Source

pub fn iter_unordered(&self) -> UnorderedIter<'_, IT, N>

Returns an iterator to read from the window.

This iterator starts at the beginning of the internal array instead of the oldest element so it does not return the elements in the order of insertion.

Trait Implementations§

Source§

impl<IT, N> Default for SlidingWindow<IT, N>
where N: Size<IT>,

Source§

fn default() -> Self

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

impl<IT, N> Index<usize> for SlidingWindow<IT, N>
where N: Size<IT>,

Source§

type Output = IT

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<IT, N> Freeze for SlidingWindow<IT, N>

§

impl<IT, N> RefUnwindSafe for SlidingWindow<IT, N>

§

impl<IT, N> Send for SlidingWindow<IT, N>
where IT: Send,

§

impl<IT, N> Sync for SlidingWindow<IT, N>
where IT: Sync,

§

impl<IT, N> Unpin for SlidingWindow<IT, N>
where <N as ArrayLength<MaybeUninit<IT>>>::ArrayType: Unpin,

§

impl<IT, N> UnwindSafe for SlidingWindow<IT, N>

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.