Skip to main content

MruList

Struct MruList 

Source
pub struct MruList<T: MruEntry> { /* private fields */ }
Expand description

A persisted MRU list backed by PersistedListModel<T>.

Cheap to clone (Rc-shared internally). The reactive ListModel<T> returned by model() is the same handle the persistence bridge observes.

Implementations§

Source§

impl<T: MruEntry> MruList<T>

Source

pub fn open( paths: &AppPaths, name: &str, max_items: usize, ) -> Result<Self, SettingsFileError>

Open at <paths.config_dir()>/<name>.toml with the default debounce window.

Creates the file (and any missing parent directories) if it does not yet exist. Use open_with_delay to override the debounce in tests.

Source

pub fn open_with_delay( paths: &AppPaths, name: &str, max_items: usize, delay: Duration, ) -> Result<Self, SettingsFileError>

Open at <paths.config_dir()>/<name>.toml with a custom debounce window.

Pass Duration::ZERO in tests to flush every mutation synchronously.

Source

pub fn open_at( path: PathBuf, max_items: usize, delay: Duration, ) -> Result<Self, SettingsFileError>

Open at an explicit path with the given debounce window.

Lower-level alternative to open when the caller already has a resolved PathBuf (e.g. from a custom directory layout).

Source

pub fn model(&self) -> &ListModel<T>

The underlying reactive list; bind to UI widgets via clones of this handle.

Read-only for mutation purposes. Use add, remove, touch, set_pinned, clear to mutate — those are what enqueue the matching persisted op. Mutating the returned ListModel directly updates what’s on screen but is never written to disk.

Source

pub fn max_items(&self) -> usize

Returns the maximum number of unpinned entries kept in the list.

Pinned entries do not count toward this cap and are never evicted automatically.

Source

pub fn add(&self, entry: T)

Insert entry at the front, deduping by entry.key(). T::touch is invoked before insertion, so the freshly-added entry reflects “now”. If a previously-pinned entry is re-added without pinned, the pin state is preserved.

Source

pub fn remove<Q>(&self, key: &Q)
where T::Key: Borrow<Q>, Q: Eq + ?Sized,

Remove the entry whose key matches, then schedule a debounced flush.

No-op when no entry with that key is present. Generic over Q so callers can pass a borrowed form of the key (e.g. &Path when T::Key = PathBuf, &str when T::Key = String) without having to allocate an owned key just to look one up.

Source

pub fn touch<Q>(&self, key: &Q)
where T::Key: Borrow<Q>, Q: Eq + ?Sized,

Mark the entry whose key matches as freshly used by calling MruEntry::touch on a clone of it, then write it back and schedule a debounced flush. No-op when no entry matches.

Source

pub fn set_pinned<Q>(&self, key: &Q, pinned: bool)
where T::Key: Borrow<Q>, Q: Eq + ?Sized,

Set the pin flag of the entry whose key matches to exactly pinned (idempotent — unlike a toggle, replaying this against an already-applied peer change does not flip it back). No-op when no entry matches.

Source

pub fn is_pinned<Q>(&self, key: &Q) -> bool
where T::Key: Borrow<Q>, Q: Eq + ?Sized,

Is the entry with this key currently pinned? false when no entry matches.

The counterpart set_pinned deliberately takes the desired value rather than toggling, because a toggle is not idempotent: replayed against a peer process’s already-applied toggle it would flip the value straight back, inverting their change. A pin button still needs to toggle, though — so read the current value here and pass its negation:

let pinned = mru.is_pinned(path);
mru.set_pinned(path, !pinned);
Source

pub fn clear(&self)

Drop every entry (pinned or not) and schedule a debounced flush.

Source

pub fn flush_now(&self) -> Result<(), SettingsFileError>

Write the list to disk synchronously, bypassing the debounce window.

Useful at app shutdown or at the end of a test to guarantee the file reflects the in-memory state before the process exits.

Source

pub fn path(&self) -> &Path

The TOML file path this list reads from and writes to.

Trait Implementations§

Source§

impl<T: MruEntry> Clone for MruList<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: MruEntry> Debug for MruList<T>

Source§

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

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

impl<T> Reloadable for MruList<T>
where T: PartialEq + MruEntry,

Source§

fn path(&self) -> &Path

The file this instance reads from and writes to. A watcher uses this to know which path to associate with which Reloadable handle.
Source§

fn reload_from_disk(&self) -> Result<bool, SettingsFileError>

Re-read the file from disk and push any genuinely new content into live signals/models. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for MruList<T>

§

impl<T> !Send for MruList<T>

§

impl<T> !Sync for MruList<T>

§

impl<T> !UnwindSafe for MruList<T>

§

impl<T> Freeze for MruList<T>

§

impl<T> Unpin for MruList<T>

§

impl<T> UnsafeUnpin for MruList<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.