Expand description
day-part-prefs — a HEADLESS cross-platform persistent key/value store. No UI; any Rust code can
depend on this crate and call set / get / remove / contains to persist small
strings across launches through the platform’s NATIVE preferences facility.
day_part_prefs::set("greeting", "hello");
assert_eq!(day_part_prefs::get("greeting").as_deref(), Some("hello"));
assert!(day_part_prefs::contains("greeting"));
day_part_prefs::remove("greeting");Platform selection is purely #[cfg(target_os)]/#[cfg(target_env)] (persistence is an OS
concern, not a widget-toolkit one): macOS and iOS share one NSUserDefaults file, Android uses
SharedPreferences (via a Java shim staged by day build), and Linux / Windows / HarmonyOS
share a file-backed store under the per-user config directory. Values persist until removed and
survive process restarts. Platforms without any store fall back to a no-op that always reports
failure/absence.
This is a small string store for user settings and lightweight app state — not a database. Keep values modest; large blobs belong in a file. See docs/prefs.md for the per-platform matrix.
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, orNoneif it is absent (or no store is available on the platform). A stored empty string isSome(""), distinct from an absent key. - install_
nav_ store - Install this prefs store as the app’s navigation-persistence store (docs/navigation.md), so a
selectororstackmarked.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 aday.nav.prefix, so.restore("mail")never collides with the app’s ownset/getkeys. - remove
- Delete the value stored under
key. Returnstrueif a value existed and was removed,falseif the key was already absent (or the delete could not be committed). - set
- Persist
valueunderkey, overwriting any previous value. Returnstruewhen the write was committed. On Apple platforms this always succeeds; on Android it reflectsSharedPreferences.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 yieldsfalse).