pub struct AutoSave { /* private fields */ }Expand description
Tracks the last-persisted serialized blob so the platform harness can avoid writing unchanged state every frame.
§Example (pseudo-Rust)
ⓘ
let mut auto_save = AutoSave::new();
loop {
paint_frame();
auto_save.tick(
mouse_buttons_held == 0,
|| state.serialize(),
|blob| std::fs::write("state.json", blob).ok(),
);
}Implementations§
Source§impl AutoSave
impl AutoSave
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create an empty auto-save tracker. First tick call will always
persist (because the last-saved blob is empty).
Sourcepub fn tick<S, P>(&mut self, idle: bool, serialize_now: S, persist: P) -> bool
pub fn tick<S, P>(&mut self, idle: bool, serialize_now: S, persist: P) -> bool
Consider persisting the current state.
idle — guard that must be true for the save to happen.
Typically mouse_buttons_held == 0; callers can layer other
conditions (e.g. “no in-flight drag”).
serialize_now — closure that produces the current serialized
blob. Only invoked when idle is true.
persist — closure that writes the blob to the platform backend
(file / localStorage / network). Only invoked when the blob
differs from the last persisted version.
Returns true iff the persist closure was called.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AutoSave
impl RefUnwindSafe for AutoSave
impl Send for AutoSave
impl Sync for AutoSave
impl Unpin for AutoSave
impl UnsafeUnpin for AutoSave
impl UnwindSafe for AutoSave
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