use crate::event_store::StreamRevision;
use crate::{AggregateRoot, Entity};
#[derive(Debug, Eq, PartialEq)]
pub struct AggregateSnapshot<S> {
state: S,
revision: StreamRevision,
}
impl<S> AggregateSnapshot<S> {
pub fn new(state: S, revision: StreamRevision) -> Self {
Self { state, revision }
}
pub fn state(&self) -> &S {
&self.state
}
pub fn revision(&self) -> StreamRevision {
self.revision
}
pub fn into_parts(self) -> (S, StreamRevision) {
(self.state, self.revision)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SnapshotUse {
Applicable,
Stale,
Inapplicable,
}
#[derive(Debug, Eq, PartialEq)]
pub enum SnapshotLoadError<E> {
Adapter(E),
}
#[derive(Debug, Eq, PartialEq)]
pub enum SnapshotSaveError<E> {
Adapter(E),
}
pub trait SnapshotStore {
type Aggregate: AggregateRoot;
type State;
type Error;
fn load(
&self,
id: &<Self::Aggregate as Entity>::Id,
) -> Result<Option<AggregateSnapshot<Self::State>>, SnapshotLoadError<Self::Error>>;
fn save(
&mut self,
id: &<Self::Aggregate as Entity>::Id,
snapshot: AggregateSnapshot<Self::State>,
) -> Result<(), SnapshotSaveError<Self::Error>>;
}