pub struct PersistedListModel<T>{ /* private fields */ }Expand description
A reactive, Keyed-item list whose mutations persist to a single
TOML file by merging ops, not by overwriting a whole-document
snapshot.
Implementations§
Source§impl<T> PersistedListModel<T>
impl<T> PersistedListModel<T>
Sourcepub fn open(
path: PathBuf,
delay: Duration,
migrator: Migrator<ListFile<T>>,
) -> Result<Self, SettingsFileError>
pub fn open( path: PathBuf, delay: Duration, migrator: Migrator<ListFile<T>>, ) -> Result<Self, SettingsFileError>
Open the file at path (running migrator, under an exclusive
lock so a peer mid-write can’t hand us a torn read), seed the model
from its contents, and retain everything needed to enqueue op
patches on every mutation.
delay is the debounce window for writes — unlike
crate::SettingsFile, this type’s writes are expected to be
frequent (every add/touch/remove on a live MRU list), so the
debounce is real and load-bearing here, not vestigial.
Sourcepub fn model(&self) -> &ListModel<T>
pub fn model(&self) -> &ListModel<T>
The underlying reactive list handle. Clone it to share with
Repeater / ListView widgets for reading. See the module
docs: mutating the returned handle directly does not persist —
use this type’s own mutation methods instead.
Sourcepub fn upsert_front(&self, item: T)
pub fn upsert_front(&self, item: T)
Insert item at the front, deduping by item.key() (removing any
existing entry with the same key first). Updates the live model
immediately and enqueues the matching ListOp::UpsertFront.
Sourcepub fn update_in_place(&self, item: T) -> bool
pub fn update_in_place(&self, item: T) -> bool
Replace the entry with item.key() in place (no reordering).
Returns false (and does nothing) if no entry with that key
exists locally. Enqueues ListOp::UpdateInPlace on success.
Sourcepub fn remove(&self, key: &T::Key) -> bool
pub fn remove(&self, key: &T::Key) -> bool
Remove the entry with this key, if present locally. Returns
whether anything was removed. Enqueues ListOp::Remove on
success.
Sourcepub fn flush_now(&self) -> Result<(), SettingsFileError>
pub fn flush_now(&self) -> Result<(), SettingsFileError>
Flush any pending op(s) to disk immediately, bypassing the debounce window. Flushes the op queue — never a re-derived snapshot of the in-memory list, which is exactly the mechanism that used to let a cleanly-exiting process erase a peer’s newly-added entry.
Trait Implementations§
Source§impl<T> Debug for PersistedListModel<T>
impl<T> Debug for PersistedListModel<T>
Source§impl<T> Reloadable for PersistedListModel<T>
impl<T> Reloadable for PersistedListModel<T>
Source§fn path(&self) -> &Path
fn path(&self) -> &Path
Reloadable handle.