1use crate::{CqrsError, RawEvent};
2
3#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
4pub enum AggregatePredicate {
5 AllAggregates(EventTypesPredicate),
6 SpecificAggregates(&'static [SpecificAggregatePredicate]),
7}
8
9impl Default for AggregatePredicate {
10 fn default() -> Self {
11 AggregatePredicate::AllAggregates(EventTypesPredicate::default())
12 }
13}
14
15#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
16pub enum EventTypesPredicate {
17 AllEventTypes,
18 SpecificEventTypes(&'static [&'static str]),
19}
20
21impl Default for EventTypesPredicate {
22 fn default() -> Self {
23 EventTypesPredicate::AllEventTypes
24 }
25}
26
27#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)]
28pub struct ReactionPredicate {
29 pub aggregate_predicate: AggregatePredicate,
30}
31
32#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)]
33pub struct SpecificAggregatePredicate {
34 pub aggregate_type: &'static str,
35 pub event_types: EventTypesPredicate,
36}
37
38pub trait Reactor {
40 fn start_reaction<R: Reaction>(reaction: R);
41 fn stop_reaction();
42}
43
44pub trait Reaction {
46 type Error: CqrsError;
47
48 fn reaction_name() -> &'static str;
49 fn react(&mut self, event: RawEvent) -> Result<(), Self::Error>;
50 fn predicate(&self) -> ReactionPredicate;
51 fn interval() -> std::time::Duration;
52}