1+ //! Contains implementations of the [event::Store] trait and connected abstractions,
2+ //! such as the [std::collections::HashMap]'s based [InMemory] Event Store implementation.
3+
14use std:: {
25 collections:: HashMap ,
36 convert:: Infallible ,
3235 }
3336}
3437
38+ /// In-memory implementation of [event::Store] trait,
39+ /// backed by a thread-safe [std::collections::HashMap].
3540#[ derive( Debug , Clone ) ]
3641pub struct InMemory < Id , Evt >
3742where
@@ -139,6 +144,11 @@ where
139144 }
140145}
141146
147+ /// Decorator type for an [event::Store] implementation that tracks the list of
148+ /// recorded Domain Events through it.
149+ ///
150+ /// Useful for testing purposes, i.e. asserting that Domain Events written throguh
151+ /// this Event Store instance are the ones expected.
142152#[ derive( Debug , Clone ) ]
143153pub struct Tracking < T , StreamId , Event >
144154where
@@ -158,13 +168,15 @@ where
158168 StreamId : Clone + Send + Sync ,
159169 Event : message:: Message + Clone + Send + Sync ,
160170{
171+ /// Returns the list of recoded Domain Events through this decorator so far.
161172 pub fn recorded_events ( & self ) -> Vec < event:: Persisted < StreamId , Event > > {
162173 self . events
163174 . read ( )
164175 . expect ( "acquire lock on recorded events list" )
165176 . clone ( )
166177 }
167178
179+ /// Resets the list of recorded Domain Events through this decorator.
168180 pub fn reset_recorded_events ( & self ) {
169181 self . events
170182 . write ( )
@@ -232,12 +244,16 @@ where
232244 }
233245}
234246
247+ /// Extension trait that can be used to pull in supertypes implemented
248+ /// in this module.
235249pub trait EventStoreExt < StreamId , Event > :
236250 event:: Store < StreamId , Event > + Send + Sync + Sized
237251where
238252 StreamId : Clone + Send + Sync ,
239253 Event : message:: Message + Clone + Send + Sync ,
240254{
255+ /// Returns a [Tracking] instance that decorates the original [event::Store]
256+ /// instanca this method has been called on.
241257 fn with_recorded_events_tracking ( self ) -> Tracking < Self , StreamId , Event > {
242258 Tracking {
243259 store : self ,
0 commit comments