pub struct Inventory { /* private fields */ }asset only.Expand description
LRU-bounded MacAddr → Asset inventory.
Asset records age out by LRU. Reads via Self::get
don’t reorder; only absorb() does. That keeps the cache
honest about what’s recently contributed to the
inventory, not what’s recently queried — the operational
distinction matters because a dashboard polling every
asset every second would otherwise hold every MAC in
memory forever.
Inventory is Send (the underlying LruCache is).
Issue #27 (0.18).
Implementations§
Source§impl Inventory
impl Inventory
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Construct with the given max capacity. A capacity of
0 is treated as 1 (the LRU library disallows
zero).
Sourcepub fn absorb(&mut self, update: Asset) -> &Asset
pub fn absorb(&mut self, update: Asset) -> &Asset
Merge update into the existing entry for
update.mac, or insert as new. Returns a reference to
the post-merge entry.
absorb is the only mutator that touches LRU order —
callers polling with get don’t keep stale records
pinned.
Sourcepub fn absorb_at(&mut self, update: Asset, ts: Timestamp) -> &Asset
pub fn absorb_at(&mut self, update: Asset, ts: Timestamp) -> &Asset
Insert update with an explicit observation timestamp.
Equivalent to setting update.last_seen = ts before
absorb.