event_sourcing/
event_store_builder.rs1use core::marker::PhantomData;
2use crate::adapter::{EventStoreAdapter, NotificationAdapter};
3use crate::{Aggregate, EventStore};
4
5pub struct EventStoreBuilder<A, E, ESA, NA> {
7 store_attempts: usize,
8 event_store_adapter: ESA,
9 notification_adapter: NA,
10 phantom_data: PhantomData<(A, E)>
11}
12
13impl<A, E> EventStoreBuilder<A, E, (), ()> {
14 pub fn new() -> Self {
15 Self {
16 store_attempts: 30,
17 event_store_adapter: (),
18 notification_adapter: (),
19 phantom_data: PhantomData
20 }
21 }
22
23 pub fn store_attempts(mut self, store_attempts: usize) -> Self {
24 self.store_attempts = store_attempts;
25 self
26 }
27}
28
29impl<A, E, ESA, NA> EventStoreBuilder<A, E, ESA, NA> {
30 pub fn event_store_adapter<T: EventStoreAdapter<A, E>>(self, event_store_adapter: T) -> EventStoreBuilder<A, E, T, NA> {
31 EventStoreBuilder {
32 event_store_adapter,
33 notification_adapter: self.notification_adapter,
34 store_attempts: self.store_attempts,
35 phantom_data: PhantomData
36 }
37 }
38
39 pub fn notification_adapter<T: NotificationAdapter<A, E>>(self, notification_adapter: T) -> EventStoreBuilder<A, E, ESA, T> {
40 EventStoreBuilder {
41 event_store_adapter: self.event_store_adapter,
42 notification_adapter,
43 store_attempts: self.store_attempts,
44 phantom_data: PhantomData
45 }
46 }
47}
48
49impl<A: Aggregate<E> + Send + Sync + Clone, E: std::marker::Send, ESA: EventStoreAdapter<A, E> + 'static, NA: NotificationAdapter<A, E> + 'static> EventStoreBuilder<A, E, ESA, NA> {
50
51 pub fn build(self) -> EventStore<A, E> {
52 EventStore::new(self.event_store_adapter, self.notification_adapter, self.store_attempts)
53 }
54}