Module persist
Expand description
Making an app’s state survive a restart.
The toolkit stays away from the disk itself —
State::save/State::load only convert to and from bytes — so
without this, each app has to invent its own storage.
This module closes that gap in three lines. Instead of
tilo_ui::App::from_factory(tilo_ui::State::new(), my_app::app_root).run();an app writes
let (state, autosave) = tilo_ui::persist::open("so.tilo.my-app");
tilo_ui::App::from_factory(state, my_app::app_root)
.with_autosave(autosave)
.run();and gets the previous session’s document loaded before the first
sync, every change written back atomically and debounced, and a
flush on exit. Where the bytes live is documented on [app_state].
The id string is a fallback: TILO_PACKAGE_ID, set by the launcher on
every sandboxed launch, always wins — without it a binary run from
target/debug would share one document with every other app.
Every function here resolves storage from the native process
environment (TILO_PACKAGE_ID, the XDG data directory) and the local
filesystem. A host with an explicit profile opens records through
crate::record::RecordOwners instead, which persists through any
durable_store::DurableStore.
Structs§
- DocStore
- One Automerge document handled by hand: load it, save or append it, and
hand it to a
DocWriterfor debounced background writes. A thin policy layer over a [DocOwner] on aDurableStore; it owns no file handling of its own. - DocWriter
- Persists one owner’s live document; see the module docs. Failures are
sticky: after one,
DocWriter::requestsends nothing until aDocWriter::request_checkpointfull save becomes durable.
Enums§
- Store
Error - Everything that can go wrong opening, reading or writing a store.
Constants§
- DEBOUNCE
- The debounce window the native store applies to
open()’s writes. - DEFAULT_
DEBOUNCE - Debounce window
FsStoreapplies by default. Long enough to swallow a burst of keystrokes, short enough that akilla moment later still finds the edit stored.
Functions§
- open
- Load this package’s persisted document and start its background writer.
- open_
canonical_ at - Open an explicitly selected canonical profile through the same private native initial-read context when one is installed. The path selects local storage only; it never supplies a document authority or changes read mode.
- open_
for - Convenience for tests and tools: same as
open()but for an explicit package id rather thanTILO_PACKAGE_ID. - open_in
open_forover an explicit store, consulting no environment.- open_
room - Open the index for one collaboration room. Record-aware applications use
this instead of
open(), so two rooms never hydrate or overwrite each other’s record references. - open_
room_ in open_roomover an explicit store and package, consulting no environment.- try_
open open()without the swallow-and-log fallback.