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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().