Struct ArrayStorage

Source
pub struct ArrayStorage<T, const SIZE: usize, const CAPACITY: usize>{ /* private fields */ }
Expand description

A highly optimized fixed-size array-based sliding window implementation

§Type Parameters

  • T - The type of elements stored in the window
  • SIZE - The size of the sliding window
  • CAPACITY - The total capacity of the underlying array

§Implementation Note

Uses a fixed-size array with constant memory footprint. The window slides through the array using head and tail pointers, with rewind operations when needed.

Implementations§

Source§

impl<T, const SIZE: usize, const CAPACITY: usize> ArrayStorage<T, SIZE, CAPACITY>

Source

pub fn new() -> Self

Creates a new ArrayStorage instance

§Returns
  • Self - A new ArrayStorage instance with initialized array and pointers
§Implementation Note

Initializes a fixed-size array with default values and sets up window tracking

Trait Implementations§

Source§

impl<T, const SIZE: usize, const CAPACITY: usize> Debug for ArrayStorage<T, SIZE, CAPACITY>

Source§

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

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

impl<T, const SIZE: usize, const CAPACITY: usize> Default for ArrayStorage<T, SIZE, CAPACITY>

Source§

fn default() -> Self

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

impl<T, const SIZE: usize, const CAPACITY: usize> WindowStorage<T> for ArrayStorage<T, SIZE, CAPACITY>

Source§

fn push(&mut self, value: T)

Pushes a new element into the sliding window

§Args
  • value - The value to be pushed into the window
§Implementation Note

Optimized for the common case with minimal branching

Source§

fn first(&self) -> Result<T, String>

Returns the first (oldest) element in the sliding window

§Returns
  • Ok(T) - The first element in the window
  • Err(String) - If the window is empty
Source§

fn last(&self) -> Result<T, String>

Returns the last (newest) element in the sliding window

§Returns
  • Ok(T) - The last element in the window
  • Err(String) - If the window is not yet filled
Source§

fn tail(&self) -> usize

Returns the current tail position of the window

Source§

fn size(&self) -> usize

Returns the size of the sliding window

Source§

fn get_slice(&self) -> &[T]

Returns a slice of the current window contents

§Returns
  • &[T] - A slice containing the current window elements
Source§

fn filled(&self) -> bool

Checks if the sliding window is filled to its maximum size

Source§

fn empty(&self) -> bool

Returns true if the window is empty Read more
Source§

fn arr<const S: usize>(&self) -> Result<[T; S], String>

Returns the sliding window as a fixed size static array Read more
Source§

fn slice(&self) -> Result<&[T], String>

Returns the sliding window as a slice Read more
Source§

fn vec(&self) -> Result<Vec<T>, String>

Returns the sliding window as a vector Read more

Auto Trait Implementations§

§

impl<T, const SIZE: usize, const CAPACITY: usize> Freeze for ArrayStorage<T, SIZE, CAPACITY>

§

impl<T, const SIZE: usize, const CAPACITY: usize> RefUnwindSafe for ArrayStorage<T, SIZE, CAPACITY>

§

impl<T, const SIZE: usize, const CAPACITY: usize> Send for ArrayStorage<T, SIZE, CAPACITY>

§

impl<T, const SIZE: usize, const CAPACITY: usize> Sync for ArrayStorage<T, SIZE, CAPACITY>

§

impl<T, const SIZE: usize, const CAPACITY: usize> Unpin for ArrayStorage<T, SIZE, CAPACITY>

§

impl<T, const SIZE: usize, const CAPACITY: usize> UnwindSafe for ArrayStorage<T, SIZE, CAPACITY>

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, 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.