Skip to main content

Snapshottable

Trait Snapshottable 

Source
pub trait Snapshottable: Aggregate {
    type Snapshot: Serialize + DeserializeOwned;

    // Required methods
    fn create_snapshot(&self) -> Self::Snapshot;
    fn restore_from_snapshot(&mut self, snapshot: Self::Snapshot);
}
Expand description

Opt-in trait for aggregates that can produce state snapshot payloads.

Aggregates implementing this trait can have their state captured as a DTO at a point in time and restored later. Repositories may serialize that payload into a snapshot cache record to skip costly full event replay, but the payload itself is not an aggregate event and is not durable history by itself.

The associated Snapshot type is a separate struct (e.g., TodoSnapshot) that captures the aggregate’s current state.

Required Associated Types§

Required Methods§

Source

fn create_snapshot(&self) -> Self::Snapshot

Create a snapshot of the current aggregate state.

Source

fn restore_from_snapshot(&mut self, snapshot: Self::Snapshot)

Restore aggregate state from a snapshot.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§