pub struct InMemoryRepository<A>where
A: AggregateRoot,{ /* private fields */ }Expand description
A thread-safe, in-memory Repository implementation for tests.
Keys aggregates by their id (A::Id: Eq + Hash + Clone) and stores cloned
state. On save it drains the aggregate’s pending events
(as a real repository would, e.g. into an outbox) and records them for later
inspection via drained_events.
Its Error is Infallible: nothing here can fail.
Implementations§
Source§impl<A> InMemoryRepository<A>
impl<A> InMemoryRepository<A>
Sourcepub fn insert(&self, aggregate: A)
pub fn insert(&self, aggregate: A)
Insert (or replace) an aggregate’s state directly, without draining its events — a convenience for seeding fixtures.
Sourcepub fn drained_events(&self) -> Vec<A::Event>
pub fn drained_events(&self) -> Vec<A::Event>
Remove and return all events captured from save calls so far.
Each save appends the aggregate’s drained events
here, preserving order across saves. Calling this clears the buffer.
Sourcepub fn drained_event_count(&self) -> usize
pub fn drained_event_count(&self) -> usize
The number of events captured from save calls (without draining them).
Trait Implementations§
Source§impl<A> Default for InMemoryRepository<A>
impl<A> Default for InMemoryRepository<A>
Source§impl<A> Repository<A> for InMemoryRepository<A>
impl<A> Repository<A> for InMemoryRepository<A>
Source§type Error = Infallible
type Error = Infallible
The error type the implementation reports.
Source§fn find<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 A::Id,
) -> Pin<Box<dyn Future<Output = Result<Option<A>, Infallible>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn find<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 A::Id,
) -> Pin<Box<dyn Future<Output = Result<Option<A>, Infallible>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Load an aggregate by id, or
None if it does not exist.Source§fn save<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate: &'life1 mut A,
) -> Pin<Box<dyn Future<Output = Result<(), Infallible>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate: &'life1 mut A,
) -> Pin<Box<dyn Future<Output = Result<(), Infallible>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Persist an aggregate. Takes
&mut so the implementation may drain its
events (e.g. into an outbox) as part of the save.Auto Trait Implementations§
impl<A> !Freeze for InMemoryRepository<A>
impl<A> RefUnwindSafe for InMemoryRepository<A>
impl<A> Send for InMemoryRepository<A>
impl<A> Sync for InMemoryRepository<A>
impl<A> Unpin for InMemoryRepository<A>
impl<A> UnsafeUnpin for InMemoryRepository<A>
impl<A> UnwindSafe for InMemoryRepository<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more