pub trait Resizable: Send + Sync {
fn name(&self) -> &str;
fn current_bytes(&self) -> u64;
fn max_bytes(&self) -> u64;
fn set_max_bytes(&self, new: u64);
fn stats(&self) -> ResizableStats;
}
#[derive(Clone, Copy, Debug, Default)]
pub struct ResizableStats {
pub hits: u64,
pub misses: u64,
pub evictions: u64,
}
impl ResizableStats {
#[must_use]
pub fn hit_rate(&self) -> Option<f64> {
let total = self.hits.checked_add(self.misses)?;
if total == 0 {
return None;
}
Some(self.hits as f64 / total as f64)
}
}