WindowStorage

Trait WindowStorage 

Source
pub trait WindowStorage<T>
where T: PartialEq + Copy + Default,
{ // Required methods fn push(&mut self, value: T); fn first(&self) -> Result<T, String>; fn last(&self) -> Result<T, String>; fn tail(&self) -> usize; fn size(&self) -> usize; fn get_slice(&self) -> &[T]; // Provided methods fn empty(&self) -> bool { ... } fn filled(&self) -> bool { ... } fn arr<const S: usize>(&self) -> Result<[T; S], String> { ... } fn slice(&self) -> Result<&[T], String> { ... } fn vec(&self) -> Result<Vec<T>, String> { ... } }
Expand description

Trait defining the interface for a sliding window data structure

§Type Parameters

  • T - The type of elements stored in the window, must implement PartialEq + Copy + Default

§Implementation Note

This trait provides both required methods that must be implemented by all window types and default implementations for common window operations.

Required Methods§

Source

fn push(&mut self, value: T)

Pushes a new element to the beginning of the sliding window

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

When the window is filled, the oldest element will be dropped to maintain the window size

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

§Returns
  • usize - The current tail position
Source

fn size(&self) -> usize

Returns the size of the sliding window

§Returns
  • usize - The configured size of the window
Source

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

Returns a slice of the current window contents

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

Provided Methods§

Source

fn empty(&self) -> bool

Returns true if the window is empty

§Returns
  • bool - True if the window is empty, false otherwise
§Implementation Note

Default implementation checks if tail position is 0

Source

fn filled(&self) -> bool

Returns true if the window is filled

§Returns
  • bool - True if the window is filled, false otherwise
§Implementation Note

Default implementation checks if tail position is at least the window size

Source

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

Returns the sliding window as a fixed size static array

§Type Parameters
  • S - The size of the returned array
§Returns
  • Ok([T; S]) - The window contents as a fixed-size array
  • Err(String) - If the window is not yet filled
§Implementation Note

Default implementation copies window contents into a new fixed-size array

Source

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

Returns the sliding window as a slice

§Returns
  • Ok(&[T]) - A slice of the window contents
  • Err(String) - If the window is not yet filled
§Implementation Note

Default implementation returns the slice only if the window is filled

Source

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

Returns the sliding window as a vector

§Returns
  • Ok(Vec<T>) - A vector containing the window contents
  • Err(String) - If the window is not yet filled
§Implementation Note

Default implementation converts the window slice to a vector

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> WindowStorage<T> for VectorStorage<T>
where T: PartialEq + Copy + Default,

Source§

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