photon_backend/
handler_descriptor.rs1use std::future::Future;
4use std::pin::Pin;
5
6use photon_core::IdentityFactory;
7
8use crate::error::Result;
9use crate::models::Event;
10
11pub type HandlerInvoker = for<'a> fn(
15 &'a dyn IdentityFactory,
16 &'a Event,
17) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
18
19#[derive(Clone, Copy)]
21pub struct HandlerDescriptor {
22 pub topic_name: &'static str,
24 pub subscription_name: &'static str,
26 pub registry_key: &'static str,
28 pub invoke: HandlerInvoker,
30 pub consumer_group: Option<&'static str>,
32 pub group_shard_count: Option<u32>,
34}
35
36impl HandlerDescriptor {
37 pub const fn new(
39 topic_name: &'static str,
40 subscription_name: &'static str,
41 registry_key: &'static str,
42 invoke: HandlerInvoker,
43 ) -> Self {
44 Self {
45 topic_name,
46 subscription_name,
47 registry_key,
48 invoke,
49 consumer_group: None,
50 group_shard_count: None,
51 }
52 }
53
54 pub const fn new_group(
56 topic_name: &'static str,
57 consumer_group: &'static str,
58 group_shard_count: Option<u32>,
59 registry_key: &'static str,
60 invoke: HandlerInvoker,
61 ) -> Self {
62 Self {
63 topic_name,
64 subscription_name: "",
65 registry_key,
66 invoke,
67 consumer_group: Some(consumer_group),
68 group_shard_count,
69 }
70 }
71
72 #[must_use]
74 pub const fn is_consumer_group(&self) -> bool {
75 self.consumer_group.is_some()
76 }
77}
78
79crate::inventory::collect!(HandlerDescriptor);
80
81impl quark::Registrable for HandlerDescriptor {
82 fn registry_key(&self) -> &str {
83 self.registry_key
84 }
85}