pub trait WindowStorage<T>{
// 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§
Sourcefn first(&self) -> Result<T, String>
fn first(&self) -> Result<T, String>
Returns the first (oldest) element in the sliding window
§Returns
Ok(T)- The first element in the windowErr(String)- If the window is empty
Sourcefn last(&self) -> Result<T, String>
fn last(&self) -> Result<T, String>
Returns the last (newest) element in the sliding window
§Returns
Ok(T)- The last element in the windowErr(String)- If the window is not yet filled
Provided Methods§
Sourcefn arr<const S: usize>(&self) -> Result<[T; S], String>
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 arrayErr(String)- If the window is not yet filled
§Implementation Note
Default implementation copies window contents into a new fixed-size array
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.