pub struct JsonFileStore { /* private fields */ }Implementations§
Source§impl JsonFileStore
impl JsonFileStore
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Examples found in repository?
examples/runtime_persistence.rs (line 21)
19fn run() -> Result<(), Box<dyn std::error::Error>> {
20 let path = temp_state_path("runtime");
21 let mut runtime = KernelRuntime::load(JsonFileStore::new(&path))?;
22
23 let receipt = runtime.write_with_receipt("apps.demo.home.count", 3_u64)?;
24 let json = runtime_receipt_to_json(&receipt);
25
26 assert_eq!(json["events"][0]["path"][0], "apps");
27 assert_eq!(json["events"][0]["path"][2], "home");
28 assert_eq!(json["events"][0]["value"], 3.0);
29
30 let restored = KernelRuntime::load(JsonFileStore::new(&path))?;
31 assert_eq!(
32 restored.read("apps.demo.home.count"),
33 Some(&Value::from(3_u64))
34 );
35 assert!(restored.events().is_empty());
36
37 println!("{json}");
38 let _ = fs::remove_file(path);
39 Ok(())
40}pub fn path(&self) -> &Path
Trait Implementations§
Source§impl Clone for JsonFileStore
impl Clone for JsonFileStore
Source§fn clone(&self) -> JsonFileStore
fn clone(&self) -> JsonFileStore
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JsonFileStore
impl Debug for JsonFileStore
Source§impl MemoryStore for JsonFileStore
impl MemoryStore for JsonFileStore
fn load_snapshot(&self) -> Result<Option<Snapshot>, StorageError>
fn save_snapshot(&self, snapshot: &Snapshot) -> Result<(), StorageError>
fn load_kernel(&self) -> Result<Kernel, StorageError>
fn save_kernel(&self, kernel: &Kernel) -> Result<(), StorageError>
Auto Trait Implementations§
impl Freeze for JsonFileStore
impl RefUnwindSafe for JsonFileStore
impl Send for JsonFileStore
impl Sync for JsonFileStore
impl Unpin for JsonFileStore
impl UnsafeUnpin for JsonFileStore
impl UnwindSafe for JsonFileStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more