sqs_lambda/
event_handler.rs

1use async_trait::async_trait;
2use std::fmt::Debug;
3
4use crate::cache::Cacheable;
5
6pub enum Completion<T, E>
7where
8    T: Clone + Send + Sync + 'static,
9    E: Debug + Send + Sync + 'static,
10{
11    Total(T),
12    Partial((T, E)),
13    Error(E),
14}
15
16pub struct OutputEvent<T, E>
17where
18    T: Clone + Send + Sync + 'static,
19    E: Debug + Send + Sync + 'static,
20{
21    pub completed_event: Completion<T, E>,
22    pub identities: Vec<Vec<u8>>,
23}
24
25impl<T, E> OutputEvent<T, E>
26where
27    T: Clone + Send + Sync + 'static,
28    E: Debug + Send + Sync + 'static,
29{
30    pub fn new(completed_event: Completion<T, E>) -> Self {
31        Self {
32            completed_event,
33            identities: Vec::new(),
34        }
35    }
36
37    pub fn add_identity(&mut self, identity: impl Cacheable) {
38        self.identities.push(identity.identity())
39    }
40}
41
42#[async_trait]
43pub trait EventHandler {
44    type InputEvent;
45    type OutputEvent: Clone + Send + Sync + 'static;
46    type Error: Debug + Send + Sync + 'static;
47
48    async fn handle_event(
49        &mut self,
50        input: Self::InputEvent,
51    ) -> OutputEvent<Self::OutputEvent, Self::Error>;
52}