cdk_common/pub_sub/
types.rs1use std::hash::Hash;
6use std::sync::Arc;
7
8use serde::de::DeserializeOwned;
9use serde::Serialize;
10
11use super::Subscriber;
12
13#[async_trait::async_trait]
15pub trait Spec: Send + Sync {
16 type Topic: Send
18 + Sync
19 + Clone
20 + Eq
21 + PartialEq
22 + Ord
23 + PartialOrd
24 + Hash
25 + Send
26 + Sync
27 + DeserializeOwned
28 + Serialize;
29
30 type Event: Event<Topic = Self::Topic>
32 + Send
33 + Sync
34 + Eq
35 + PartialEq
36 + DeserializeOwned
37 + Serialize;
38
39 type SubscriptionId: Clone
41 + Default
42 + Eq
43 + PartialEq
44 + Ord
45 + PartialOrd
46 + Hash
47 + Send
48 + Sync
49 + DeserializeOwned
50 + Serialize;
51
52 type Context;
54
55 fn new_instance(context: Self::Context) -> Arc<Self>
57 where
58 Self: Sized;
59
60 async fn fetch_events(
63 self: &Arc<Self>,
64 topics: Vec<<Self::Event as Event>::Topic>,
65 reply_to: Subscriber<Self>,
66 ) where
67 Self: Sized;
68}
69
70pub trait Event: Clone + Send + Sync + Eq + PartialEq + DeserializeOwned + Serialize {
72 type Topic;
77
78 fn get_topics(&self) -> Vec<Self::Topic>;
80}