Expand description
Persisted documents (ADR 0008): every document is a JSON object with a
"version" (missing means 0) and a "kind". A Schema knows the
current version and one migration per older one; loading migrates,
then deserializes. No I/O here: the persistence driver of
egui-pop-core reads and writes the text.
use egui_pop_model::doc::Schema;
use serde_json::json;
// Version 2 renamed `colour` to `color`.
let schema = Schema::new("prefs", 2)
.migration(0, |j| Ok(j))
.migration(1, |mut j| {
let c = j["colour"].take();
j["color"] = c;
Ok(j)
});
let loaded = schema
.load::<serde_json::Value>(r#"{"version": 1, "kind": "prefs", "colour": "red"}"#)
.unwrap();
assert_eq!(loaded.value["color"], json!("red"));
assert_eq!(loaded.from_version, 1);Structs§
Enums§
- DocError
- Why a document could not be loaded.
Type Aliases§
- Migration
- A migration from one version to the next.