pub struct MeasurementCache { /* private fields */ }Expand description
Cache for storing measured item sizes keyed by VirtualKey.
Maintains a mapping from item keys to their actual measured dimensions. Using keys instead of indices means measured sizes follow items across reorders when a custom key extractor is used.
Implementations§
Source§impl MeasurementCache
impl MeasurementCache
Sourcepub fn new(initial_estimate: f64) -> Self
pub fn new(initial_estimate: f64) -> Self
Creates a new empty measurement cache.
§Parameters
initial_estimate: The default size estimate used before measurements arrive.
Sourcepub fn record(
&mut self,
key: VirtualKey,
size: f64,
) -> Result<bool, VirtualizerError>
pub fn record( &mut self, key: VirtualKey, size: f64, ) -> Result<bool, VirtualizerError>
Records a measured size for the given item key.
Updates the running average and stores the measurement. If a measurement already exists for this key, it is replaced.
§Parameters
key: The item key to record a measurement for.size: The measured size in pixels.
§Returns
Ok(bool): True if the measurement changed the stored value.Err(VirtualizerError): If the size is invalid.
§Errors
- Returns
MeasurementErrorif size is negative, NaN, or infinite.
Sourcepub fn get(&self, key: &VirtualKey) -> Option<f64>
pub fn get(&self, key: &VirtualKey) -> Option<f64>
Sourcepub fn count(&self) -> usize
pub fn count(&self) -> usize
Returns the total number of stored measurements.
§Returns
usize: The count of recorded measurements.
Trait Implementations§
Source§impl Clone for MeasurementCache
impl Clone for MeasurementCache
Source§fn clone(&self) -> MeasurementCache
fn clone(&self) -> MeasurementCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MeasurementCache
impl Debug for MeasurementCache
Auto Trait Implementations§
impl Freeze for MeasurementCache
impl RefUnwindSafe for MeasurementCache
impl Send for MeasurementCache
impl Sync for MeasurementCache
impl Unpin for MeasurementCache
impl UnsafeUnpin for MeasurementCache
impl UnwindSafe for MeasurementCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more