Skip to main content

Snapshottable

Trait Snapshottable 

Source
pub trait Snapshottable {
    // Required methods
    fn snapshot(&self) -> ComponentSnapshot;
    fn restore(
        &mut self,
        snapshot: &ComponentSnapshot,
    ) -> Result<(), SnapshotError>;

    // Provided method
    fn has_state(&self) -> bool { ... }
}
Expand description

Trait for components that support state persistence.

Implementing this trait allows a component’s state to be saved when a session is paused and restored when resumed.

§Contract

  • snapshot() must produce a complete representation of the component’s state
  • restore() must return the component to the exact state represented by the snapshot
  • Restored components must behave identically to their pre-snapshot state

§Thread Safety

Both methods take &self / &mut self as appropriate and don’t require additional synchronization.

Required Methods§

Source

fn snapshot(&self) -> ComponentSnapshot

Creates a snapshot of the current state.

The snapshot should contain all information needed to restore the component to its current state.

Source

fn restore(&mut self, snapshot: &ComponentSnapshot) -> Result<(), SnapshotError>

Restores state from a snapshot.

§Errors

Returns SnapshotError if restoration fails (version mismatch, invalid data, etc.).

Provided Methods§

Source

fn has_state(&self) -> bool

Returns true if this component has meaningful state to persist.

Components that always start fresh can return false to skip snapshot/restore operations.

Implementors§