euv-core 0.18.8

A declarative, cross-platform UI framework for Rust with virtual DOM, reactive signals, and HTML macros for WebAssembly.
Documentation
use super::*;

/// A fixed-capacity LRU cache.
///
/// The cache holds at most `capacity` entries. When a
/// `put` would exceed the capacity, the
/// least-recently-used entry is evicted. `get` updates
/// the recency so the just-read entry becomes the most-
/// recently-used.
///
/// All operations are O(1) amortized (`put`, `get`,
/// `remove`, `contains`) except `iter`, which is O(n).
///
/// # Capacity edge cases
///
/// - `capacity = 0` - the cache accepts no entries. Both
///   `put` and `get` behave as no-ops (well, `get` still
///   evicts because there's nothing to evict; `put`
///   silently drops the entry).
/// - `capacity = 1` - the cache holds exactly one entry.
///   Every `put` evicts the previous entry.
///
/// # Lombok `New` derivation
///
/// `#[derive(New)]` generates `LruCache::new(capacity)` —
/// the `map` and `order` fields are skipped with
/// `#[new(skip)]` so Lombok falls back to
/// `<HashMap as Default>::default()` and
/// `<VecDeque as Default>::default()` (which both call
/// `new()` internally), preserving the canonical
/// single-argument call site.
#[derive(Clone, Data, Debug, New)]
pub struct LruCache<K, V>
where
    K: Clone + Eq + Hash,
{
    /// The maximum number of entries before eviction
    /// kicks in.
    #[get(pub(crate))]
    pub(crate) capacity: usize,
    /// The current entries, keyed by K. Default-initialised
    /// via `#[new(skip)]` (`HashMap::new()`).
    #[new(skip)]
    pub(crate) map: HashMap<K, V>,
    /// The MRU-first order. Front = most recently used,
    /// back = least recently used. Default-initialised
    /// via `#[new(skip)]` (`VecDeque::new()`).
    #[new(skip)]
    pub(crate) order: VecDeque<K>,
}