Skip to main content

Module prefs

Module prefs 

Source
Expand description

Persistent settings (docs/prefs.md): a small key/value string store backed by each platform’s native facility — NSUserDefaults on Apple, SharedPreferences on Android, a file store elsewhere. day::prefs::{get, set, remove, contains}, plus bind to persist a Signal and install_nav_store to make .restore(key) navigation survive a relaunch (docs/navigation.md).

Promoted into the facade rather than left a satellite because it is what nearly every app reaches for first, and because it is the one part that lives in the reactive layer. It stays its own crate (day-part-prefs), so existing day_part_prefs::… paths keep working; this is the same API under a shorter name. Opt out with default-features = false.

Functions§

bind
Two-way-bind a signal to a stored preference: seed the signal from the store now (when a stored value exists and parses as T), then persist every later change. Call it right after creating the signal, before anything reads it. The write-back lives in the current reactive scope, so it stops with the page that created the signal.
contains
Whether a value is currently stored under key.
get
Read the string stored under key, or None if it is absent (or no store is available on the platform). A stored empty string is Some(""), distinct from an absent key.
install_nav_store
Install this prefs store as the app’s navigation-persistence store (docs/navigation.md), so a selector or stack marked .restore(key) remembers its state across launches (and across an Android process death, since the store is disk-backed). Call once at startup, before the UI mounts. Nav keys are namespaced under a day.nav. prefix, so .restore("mail") never collides with the app’s own set/get keys.
remove
Delete the value stored under key. Returns true if a value existed and was removed, false if the key was already absent (or the delete could not be committed).
set
Persist value under key, overwriting any previous value. Returns true when the write was committed. On Apple platforms this always succeeds; on Android it reflects SharedPreferences.Editor.commit(); on the file-backed platforms it reflects whether the store file could be written (a missing config directory or a read-only home yields false).
Day API ↩ Guides· daybrite.dev