pub struct PickerMruIndex { /* private fields */ }Expand description
Picker-owned MRU index. Stored host-side as
Arc<RwLock<PickerMruIndex>>; sources never touch it.
record mutates; lookup is read-only.
Implementations§
Source§impl PickerMruIndex
impl PickerMruIndex
pub fn new() -> Self
pub fn with_cap(cap_per_namespace: usize) -> Self
Sourcepub fn record(&mut self, source_id: &str, identity: &str)
pub fn record(&mut self, source_id: &str, identity: &str)
Record one accept of identity from source source_id.
If the key already exists, bumps last_used to now and
increments use_count. Otherwise creates a fresh entry,
evicting the lowest-frecency entry in the same source
namespace if at cap.
Sourcepub fn record_at(&mut self, source_id: &str, identity: &str, now: SystemTime)
pub fn record_at(&mut self, source_id: &str, identity: &str, now: SystemTime)
Like Self::record but with a caller-supplied now.
Test fixture; production callers use record so the
timestamp ordering is monotonic.
Sourcepub fn lookup(&self, source_id: &str, identity: &str) -> Option<&MruEntry>
pub fn lookup(&self, source_id: &str, identity: &str) -> Option<&MruEntry>
Look up the MRU entry for (source_id, identity).
None means “never accepted” – the candidate gets a
0.0 bonus on score combine.
Sourcepub fn frecency_bonus(
&self,
source_id: &str,
identity: &str,
now: SystemTime,
half_life: Duration,
) -> f64
pub fn frecency_bonus( &self, source_id: &str, identity: &str, now: SystemTime, half_life: Duration, ) -> f64
Compute the frecency bonus a candidate identified by
(source_id, identity) should receive when scored at
now. Returns 0.0 when there’s no entry.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drop every recorded entry. Used by tests + the
picker.mru.persist = false boot path that doesn’t
load a prior cache.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&MruKey, &MruEntry)> + '_
pub fn iter(&self) -> impl Iterator<Item = (&MruKey, &MruEntry)> + '_
Iterate every entry. Used by persistence (slice 14b)
and :describe-picker introspection.
Sourcepub fn save_to(&self, path: &Path) -> Result<(), MruPersistError>
pub fn save_to(&self, path: &Path) -> Result<(), MruPersistError>
Encode + write the index to path. Atomic at the
filesystem level: writes to <path>.tmp first then
renames into place so a crash mid-write never leaves a
truncated cache. Errors surface as Err(_) for the
host to log + retry on the next accept.
Sourcepub fn load_from(path: &Path) -> Result<Option<Self>, MruPersistError>
pub fn load_from(path: &Path) -> Result<Option<Self>, MruPersistError>
Read + decode an index from path. Returns Ok(None)
when the file doesn’t exist (fresh install). Returns
Err for IO or decode failures so the host can decide
whether to discard + start fresh or surface the error.
The default boot policy (slice 14c) is “discard +
start fresh” – losing MRU is annoying, refusing to
boot is worse.