EventStore

Struct EventStore 

Source
pub struct EventStore<E, B = InMemoryBackend<E>>
where E: Event, B: EventStoreBackend<E>,
{ /* private fields */ }
Expand description

Event Store - append-only log of domain events

The EventStore uses a pluggable backend architecture:

  • Default: InMemoryBackend (for testing/MVP)
  • Production: AllSourceBackend (requires cqrs-allsource feature)

Implementations§

Source§

impl<E> EventStore<E>
where E: Event,

Source

pub fn new() -> EventStore<E>

Create a new event store with in-memory backend

Source§

impl<E, B> EventStore<E, B>
where E: Event, B: EventStoreBackend<E>,

Source

pub fn with_backend(backend: B) -> EventStore<E, B>

Create a new event store with a custom backend

Source

pub fn backend(&self) -> &B

Get a reference to the backend

Source

pub async fn append( &self, aggregate_id: &str, events: Vec<E>, ) -> Result<(), String>

Append events to an aggregate’s event stream

Source

pub async fn get_events(&self, aggregate_id: &str) -> Result<Vec<E>, String>

Get all events for an aggregate

Source

pub async fn get_all_events(&self) -> Result<Vec<E>, String>

Get all events from all aggregates (for projection rebuild)

Source

pub async fn get_events_after( &self, aggregate_id: &str, version: u64, ) -> Result<Vec<E>, String>

Get events after a specific version (for snapshot optimization)

Source

pub async fn subscribe(&self, tx: Sender<E>)

Subscribe to event stream

Source

pub async fn save_snapshot<A>( &self, aggregate_id: &str, snapshot: Snapshot<A>, ) -> Result<(), String>
where A: Aggregate<Event = E> + Serialize,

Save a snapshot

Source

pub async fn get_latest_snapshot<A>( &self, aggregate_id: &str, ) -> Result<Snapshot<A>, String>
where A: Aggregate<Event = E> + DeserializeOwned,

Get latest snapshot

Source

pub async fn flush(&self) -> Result<(), String>

Flush pending writes to storage (useful with WAL or batching backends)

Source

pub async fn stats(&self) -> BackendStats

Get backend statistics

Trait Implementations§

Source§

impl<E, B> Clone for EventStore<E, B>
where E: Clone + Event, B: Clone + EventStoreBackend<E>,

Source§

fn clone(&self) -> EventStore<E, B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E> Default for EventStore<E>
where E: Event,

Source§

fn default() -> EventStore<E>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E, B> Freeze for EventStore<E, B>

§

impl<E, B = InMemoryBackend<E>> !RefUnwindSafe for EventStore<E, B>

§

impl<E, B> Send for EventStore<E, B>

§

impl<E, B> Sync for EventStore<E, B>

§

impl<E, B> Unpin for EventStore<E, B>
where E: Unpin,

§

impl<E, B = InMemoryBackend<E>> !UnwindSafe for EventStore<E, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more