Skip to main content

SnapshotSession

Trait SnapshotSession 

Source
pub trait SnapshotSession: Session {
    type Snapshot: Send + Sync;

    // Required methods
    fn snapshot(&self) -> Result<Self::Snapshot, Error>;
    fn restore(&mut self, snapshot: &Self::Snapshot) -> Result<(), Error>;
}
Expand description

Trait for sessions that support state snapshots.

Snapshots capture the current state of the session so it can be:

  • Persisted to disk or a database
  • Sent over the network to another process
  • Restored later to continue execution

§Snapshot Timing

Snapshots can only be captured when execute() has returned. It is not possible to snapshot mid-execution (e.g., while Python code is running). This is a fundamental limitation of JIT-compiled WASM.

§Implementation Note

The recommended approach for snapshots is the WIT export method, where Python-level state is serialized via pickle and exposed through snapshot_state() and restore_state() exports in the runtime.

Required Associated Types§

Source

type Snapshot: Send + Sync

The type of snapshot produced by this session.

Required Methods§

Source

fn snapshot(&self) -> Result<Self::Snapshot, Error>

Capture a snapshot of the current session state.

The snapshot can later be restored using SnapshotSession::restore or used to create a new session with the captured state.

§Errors

Returns an error if the snapshot cannot be captured.

Source

fn restore(&mut self, snapshot: &Self::Snapshot) -> Result<(), Error>

Restore session state from a snapshot.

This replaces the current session state with the state from the snapshot.

§Errors

Returns an error if the snapshot is invalid or incompatible with this session.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§