Expand description
The persistence driver (ADR 0008): documents saved atomically with one backup, loaded through their schema’s migrations, falling back to the backup when the main file is missing or unreadable.
use egui_pop_core::persist::Persist;
use egui_pop_model::values::{SettingsDoc, settings_schema};
let dir = std::env::temp_dir().join(format!("egui-pop-doc-{}", std::process::id()));
let persist = Persist::new(&dir);
persist.save("settings", &settings_schema(), &SettingsDoc::default()).unwrap();
let back = persist.load::<SettingsDoc>("settings", &settings_schema()).unwrap().unwrap();
assert!(back.value.values.is_empty());A Writer writes documents a short while after their last change
(debounced, about a second), so what the user changed survives a
crash and nothing waits for the exit:
use egui_pop_core::persist::{Persist, Writer};
let dir = std::env::temp_dir().join(format!("egui-pop-writer-{}", std::process::id()));
let mut w = Writer::new(Persist::new(&dir), 1.0);
assert!(w.offer("view", "{\"a\": 1}".into(), 10.0));
assert!(w.offer("view", "{\"a\": 2}".into(), 10.5)); // the deadline moves
assert!(w.tick(11.0).is_empty());
assert_eq!(w.tick(11.5).len(), 1);
assert!(!w.offer("view", "{\"a\": 2}".into(), 12.0)); // written alreadyStructs§
- Persist
- Documents in a directory:
<name>.json, its backup<name>.json.bakand, while writing,<name>.json.tmp. - Read
- A document loaded from disk.
- Writer
- Writes documents a short while after their last change: each offer of
a new text moves its deadline (
delayseconds later, at most five delays after the first unwritten change); an offer of what was written last does nothing. Times are the caller’s clock, in seconds (motion::nowin an application). Writes are atomic (Persist::save_text).
Enums§
- Persist
Error - Why a document could not be read or written.
- Source
- Which file a document came from.