Store

Struct Store 

Source
pub struct Store<Id, C, M>
where C: Codec,
{ /* private fields */ }
Expand description

In-memory event store that keeps streams in a hash map.

Uses a global sequence counter (Position = u64) to maintain chronological ordering across streams, enabling cross-aggregate projections that need to interleave events by time rather than by stream name.

Generic over:

  • Id: Aggregate identifier type (must be hashable/equatable for map keys)
  • C: Serialization codec
  • M: Metadata type (use () when not needed)

Implementations§

Source§

impl<Id, C, M> Store<Id, C, M>
where C: Codec,

Source

pub fn new(codec: C) -> Self

Trait Implementations§

Source§

impl<Id, C, M> EventStore for Store<Id, C, M>
where Id: Clone + Eq + Hash + Send + Sync + 'static, C: Codec + Clone + Send + Sync + 'static, M: Clone + Send + Sync + 'static,

Source§

type Codec = C

Serialization codec.
Source§

type Error = InMemoryError

Store-specific error type.
Source§

type Id = Id

Aggregate identifier type. Read more
Source§

type Metadata = M

Metadata type for infrastructure concerns.
Source§

type Position = u64

Position type used for ordering events and version checking. Read more
Source§

fn codec(&self) -> &Self::Codec

Source§

fn stream_version<'a>( &'a self, aggregate_kind: &'a str, aggregate_id: &'a Self::Id, ) -> impl Future<Output = Result<Option<u64>, Self::Error>> + Send + 'a

Get the current version (latest position) for an aggregate stream. Read more
Source§

fn begin<Conc: ConcurrencyStrategy>( &mut self, aggregate_kind: &str, aggregate_id: Self::Id, expected_version: Option<Self::Position>, ) -> Transaction<'_, Self, Conc>

Begin a transaction for appending events to an aggregate. Read more
Source§

fn append<'a>( &'a mut self, aggregate_kind: &'a str, aggregate_id: &'a Self::Id, expected_version: Option<u64>, events: Vec<PersistableEvent<Self::Metadata>>, ) -> impl Future<Output = Result<(), AppendError<u64, Self::Error>>> + Send + 'a

Append events with optional version checking. Read more
Source§

fn append_expecting_new<'a>( &'a mut self, aggregate_kind: &'a str, aggregate_id: &'a Self::Id, events: Vec<PersistableEvent<Self::Metadata>>, ) -> impl Future<Output = Result<(), AppendError<u64, Self::Error>>> + Send + 'a

Append events expecting an empty stream. Read more
Source§

fn load_events<'a>( &'a self, filters: &'a [EventFilter<Self::Id, Self::Position>], ) -> impl Future<Output = Result<Vec<StoredEvent<Id, u64, M>>, Self::Error>> + Send + 'a

Load events matching the specified filters. Read more

Auto Trait Implementations§

§

impl<Id, C, M> Freeze for Store<Id, C, M>
where C: Freeze,

§

impl<Id, C, M> RefUnwindSafe for Store<Id, C, M>

§

impl<Id, C, M> Send for Store<Id, C, M>
where C: Send, Id: Send, M: Send,

§

impl<Id, C, M> Sync for Store<Id, C, M>
where C: Sync, Id: Sync, M: Sync,

§

impl<Id, C, M> Unpin for Store<Id, C, M>
where C: Unpin, Id: Unpin, M: Unpin,

§

impl<Id, C, M> UnwindSafe for Store<Id, C, M>
where C: UnwindSafe, Id: UnwindSafe, M: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

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
§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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