pub(crate) mod codec;
pub(crate) mod effect;
pub(crate) mod event_sourced;
pub(crate) mod persistence_id;
pub(crate) mod schema_version;
pub(crate) mod seq_no;
pub(crate) mod spawn;
pub(crate) mod store;
pub(crate) mod versioned;
use crate::persistence::{
codec::{Cbor, Codec},
store::{EventStore, NoSnapshots, SnapshotStore},
};
#[derive(Debug, Clone)]
pub struct Persistence<E, S = NoSnapshots, C = Cbor> {
pub(crate) event_store: E,
pub(crate) snapshot_store: S,
pub(crate) codec: C,
}
impl<E> Persistence<E>
where
E: EventStore,
{
pub fn new(event_store: E) -> Self {
Self {
event_store,
snapshot_store: NoSnapshots,
codec: Cbor,
}
}
}
impl<E, S, C> Persistence<E, S, C> {
pub fn with_snapshot_store<T>(self, snapshot_store: T) -> Persistence<E, T, C>
where
T: SnapshotStore,
{
Persistence {
event_store: self.event_store,
snapshot_store,
codec: self.codec,
}
}
pub fn with_codec<T>(self, codec: T) -> Persistence<E, S, T>
where
T: Codec,
{
Persistence {
event_store: self.event_store,
snapshot_store: self.snapshot_store,
codec,
}
}
}