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 staterestore()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§
Sourcefn snapshot(&self) -> ComponentSnapshot
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.
Sourcefn restore(&mut self, snapshot: &ComponentSnapshot) -> Result<(), SnapshotError>
fn restore(&mut self, snapshot: &ComponentSnapshot) -> Result<(), SnapshotError>
Restores state from a snapshot.
§Errors
Returns SnapshotError if restoration fails (version mismatch,
invalid data, etc.).