pub struct MemStore<A: Aggregate + Send + Sync> { /* private fields */ }
Expand description
Simple memory store useful for application development and testing purposes.
Creation and use in a constructing a CqrsFramework
:
use cqrs_es::CqrsFramework;
use cqrs_es::mem_store::MemStore;
let store = MemStore::<MyAggregate>::default();
let cqrs = CqrsFramework::new(store, vec![], MyService);
Implementations§
source§impl<A: Aggregate> MemStore<A>
impl<A: Aggregate> MemStore<A>
sourcepub fn get_events(&self) -> Arc<RwLock<HashMap<String, Vec<EventEnvelope<A>>>>>
👎Deprecated since 0.4.9: clone the MemStore instead
pub fn get_events(&self) -> Arc<RwLock<HashMap<String, Vec<EventEnvelope<A>>>>>
Get a shared copy of the events stored within the event store.
This can be used to verify the state of events that have been committed. Example of reading and displaying stored events:
let store = MemStore::<MyAggregate>::default();
//...
let all_locked_events = store.get_events();
let unlocked_events = all_locked_events.read().unwrap();
if let Some(events) = unlocked_events.get("test-aggregate-id-C450D1A") {
for event in events {
println!("{:?}", event);
}
};
Trait Implementations§
source§impl<A: Aggregate> EventStore<A> for MemStore<A>
impl<A: Aggregate> EventStore<A> for MemStore<A>
§type AC = MemStoreAggregateContext<A>
type AC = MemStoreAggregateContext<A>
Provides the current state of an aggregate along with surrounding context.
This is used by the CqrsFramework when loading
an aggregate in order to handle incoming commands.
source§fn load_events<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Vec<EventEnvelope<A>>, AggregateError<A::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_events<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Vec<EventEnvelope<A>>, AggregateError<A::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Load all events for a particular
aggregate_id
source§fn load_aggregate<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<MemStoreAggregateContext<A>, AggregateError<A::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_aggregate<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<MemStoreAggregateContext<A>, AggregateError<A::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Load aggregate at current state
source§fn commit<'life0, 'async_trait>(
&'life0 self,
events: Vec<A::Event>,
context: MemStoreAggregateContext<A>,
metadata: HashMap<String, String>
) -> Pin<Box<dyn Future<Output = Result<Vec<EventEnvelope<A>>, AggregateError<A::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn commit<'life0, 'async_trait>(
&'life0 self,
events: Vec<A::Event>,
context: MemStoreAggregateContext<A>,
metadata: HashMap<String, String>
) -> Pin<Box<dyn Future<Output = Result<Vec<EventEnvelope<A>>, AggregateError<A::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Commit new events
Auto Trait Implementations§
impl<A> RefUnwindSafe for MemStore<A>
impl<A> Send for MemStore<A>
impl<A> Sync for MemStore<A>
impl<A> Unpin for MemStore<A>
impl<A> UnwindSafe for MemStore<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