Skip to main content

Module persist

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 DocWriter for debounced background writes. A thin policy layer over a [DocOwner] on a DurableStore; 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::request sends nothing until a DocWriter::request_checkpoint full save becomes durable.

Enums§

StoreError
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 FsStore applies by default. Long enough to swallow a burst of keystrokes, short enough that a kill a 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 than TILO_PACKAGE_ID.
open_in
open_for over 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_room over an explicit store and package, consulting no environment.
try_open
open() without the swallow-and-log fallback.