Skip to main content

Registry

Struct Registry 

Source
pub struct Registry { /* private fields */ }
Expand description

The in-memory model store, backed by <directory>/models.json. Every mutating method acquires a short-held advisory file lock, reloads the on-disk state under it, applies the change, and persists before returning — so two instances on the same directory serialize their writes instead of one silently clobbering the other. The lock is held only for the span of a single mutation, never across the instance’s lifetime.

Implementations§

Source§

impl Registry

Source

pub fn open(directory: &Path) -> Result<Self, RegistryError>

Open the registry rooted at directory, loading models.json if present. A missing store opens empty; a corrupt store is quarantined and reported as RegistryError::CorruptStore; a store from a newer schema is left in place and reported as RegistryError::FutureSchema. If the file holds two records with the same id, the last one in file order wins.

Source

pub fn refresh(&mut self) -> Result<bool, RegistryError>

Re-read the store, picking up what another process has committed since this one loaded it. Returns whether anything changed.

The in-memory view is otherwise only reloaded under a mutation, which is enough while one process owns the shelf. A pull worker registering what it fetched is another process, and a screen that never re-read would show a download as landed with the model nowhere on its shelf.

Source

pub fn get(&self, id: &str) -> Option<&ModelRecord>

The record with id, if present.

Source

pub fn contains(&self, id: &str) -> bool

Whether a record with id is present.

Source

pub fn len(&self) -> usize

The number of records held.

Source

pub fn is_empty(&self) -> bool

Whether the registry holds no records.

Source

pub fn generation(&self) -> u64

A counter that advances every time Self::save persists a change. Callers can cache work derived from the registry’s contents keyed on this value and rebuild only when it moves.

Source

pub fn list(&self) -> Vec<&ModelRecord>

Every record, sorted by display name (case-insensitive) then id.

Source

pub fn register(&mut self, record: ModelRecord) -> Result<bool, RegistryError>

Insert or replace record. Returns whether anything changed; an identical record is a no-op that touches no disk.

Source

pub fn register_all( &mut self, records: Vec<ModelRecord>, ) -> Result<usize, RegistryError>

Insert or replace many records, writing once. Returns how many input records differed from the store (counted per input record, so two inputs with the same id both count even though only the last survives).

Source

pub fn unregister( &mut self, id: &str, ) -> Result<Option<ModelRecord>, RegistryError>

Remove the record with id, returning it if it was present.

Source

pub fn set_state_if_present( &mut self, id: &str, state: ModelState, ) -> Result<bool, RegistryError>

Set the lifecycle state of id if it is present. Returns whether the record was present; only a real state change touches disk.

Source

pub fn update( &mut self, ids: &[String], transform: impl Fn(&ModelRecord) -> Option<ModelRecord>, ) -> Result<Vec<ModelRecord>, RegistryError>

Apply transform to each present id. When it returns a record that differs from the current one, the record is stored under its own id — if the transform changed the id, the old key is removed so the record migrates cleanly rather than leaving the map keyed by a stale id. Returns the changed records; writes once if anything changed.

Trait Implementations§

Source§

impl Debug for Registry

Source§

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

Formats the value using the given formatter. 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.

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.