rustack_ses_http/
dispatch.rs1use std::{future::Future, pin::Pin, sync::Arc};
4
5use bytes::Bytes;
6use rustack_ses_model::{error::SesError, operations::SesOperation};
7
8use crate::body::SesResponseBody;
9
10pub trait SesHandler: Send + Sync + 'static {
15 fn handle_operation(
17 &self,
18 op: SesOperation,
19 body: Bytes,
20 ) -> Pin<Box<dyn Future<Output = Result<http::Response<SesResponseBody>, SesError>> + Send>>;
21
22 fn handle_v2_operation(
24 &self,
25 method: http::Method,
26 path: String,
27 body: Bytes,
28 ) -> Pin<Box<dyn Future<Output = Result<http::Response<SesResponseBody>, SesError>> + Send>>;
29
30 fn query_emails(&self, filter_id: Option<&str>, filter_source: Option<&str>) -> String;
34
35 fn clear_emails(&self, filter_id: Option<&str>);
37}
38
39pub async fn dispatch_operation<H: SesHandler>(
41 handler: &H,
42 op: SesOperation,
43 body: Bytes,
44) -> Result<http::Response<SesResponseBody>, SesError> {
45 tracing::debug!(operation = %op, "dispatching SES operation");
46 handler.handle_operation(op, body).await
47}
48
49#[derive(Debug, Clone)]
51pub struct SesHandlerRef<H: SesHandler> {
52 inner: Arc<H>,
53}
54
55impl<H: SesHandler> SesHandlerRef<H> {
56 pub fn new(handler: Arc<H>) -> Self {
58 Self { inner: handler }
59 }
60
61 #[must_use]
63 pub fn handler(&self) -> &H {
64 &self.inner
65 }
66}