Skip to main content

EventStore

Trait EventStore 

Source
pub trait EventStore<E: Clone> {
    // Required methods
    fn append(
        &mut self,
        stream: &StreamId,
        expected: ExpectedVersion,
        events: &[NewEvent<E>],
    ) -> Result<Vec<StoredEvent<E>>>;
    fn load_stream(
        &self,
        stream: &StreamId,
        after: Option<u64>,
    ) -> Vec<StoredEvent<E>>;
    fn load_all(&self, after: Option<u64>, limit: usize) -> Vec<StoredEvent<E>>;
    fn stream_version(&self, stream: &StreamId) -> Option<u64>;
    fn len(&self) -> usize;

    // Provided methods
    fn append_owned(
        &mut self,
        stream: &StreamId,
        expected: ExpectedVersion,
        events: Vec<NewEvent<E>>,
    ) -> Result<Vec<StoredEvent<E>>> { ... }
    fn is_empty(&self) -> bool { ... }
}

Required Methods§

Source

fn append( &mut self, stream: &StreamId, expected: ExpectedVersion, events: &[NewEvent<E>], ) -> Result<Vec<StoredEvent<E>>>

Atomically appends a batch to one stream.

§Errors

Returns a version conflict, duplicate event, or capacity error without committing a partial batch.

Source

fn load_stream( &self, stream: &StreamId, after: Option<u64>, ) -> Vec<StoredEvent<E>>

Source

fn load_all(&self, after: Option<u64>, limit: usize) -> Vec<StoredEvent<E>>

Source

fn stream_version(&self, stream: &StreamId) -> Option<u64>

Source

fn len(&self) -> usize

Provided Methods§

Source

fn append_owned( &mut self, stream: &StreamId, expected: ExpectedVersion, events: Vec<NewEvent<E>>, ) -> Result<Vec<StoredEvent<E>>>

Appends an owned batch without requiring callers to retain the inputs.

Stores may override this to move payloads into committed envelopes and avoid the input clone required by Self::append.

§Errors

Returns the same version, duplicate-event, capacity, or persistence errors as Self::append.

Source

fn is_empty(&self) -> bool

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<E, C> EventStore<E> for FileEventStore<E, C>
where E: Clone, C: Codec<StoredEvent<E>>,

Source§

impl<E: Clone> EventStore<E> for InMemoryStore<E>