Skip to main content

PickerMruIndex

Struct PickerMruIndex 

Source
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

Source

pub fn new() -> Self

Source

pub fn with_cap(cap_per_namespace: usize) -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn iter(&self) -> impl Iterator<Item = (&MruKey, &MruEntry)> + '_

Iterate every entry. Used by persistence (slice 14b) and :describe-picker introspection.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for PickerMruIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PickerMruIndex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more