rustack_logs_http/
dispatch.rs1use std::{future::Future, pin::Pin};
4
5use bytes::Bytes;
6use rustack_logs_model::{error::LogsError, operations::LogsOperation};
7
8use crate::body::LogsResponseBody;
9
10pub trait LogsHandler: Send + Sync + 'static {
16 fn handle_operation(
18 &self,
19 op: LogsOperation,
20 body: Bytes,
21 ) -> Pin<Box<dyn Future<Output = Result<http::Response<LogsResponseBody>, LogsError>> + Send>>;
22}
23
24pub async fn dispatch_operation<H: LogsHandler>(
26 handler: &H,
27 op: LogsOperation,
28 body: Bytes,
29) -> Result<http::Response<LogsResponseBody>, LogsError> {
30 tracing::debug!(operation = %op, "dispatching CloudWatch Logs operation");
31 handler.handle_operation(op, body).await
32}
33
34#[derive(Debug, Clone, Default)]
36pub struct NotImplementedHandler;
37
38impl LogsHandler for NotImplementedHandler {
39 fn handle_operation(
40 &self,
41 op: LogsOperation,
42 _body: Bytes,
43 ) -> Pin<Box<dyn Future<Output = Result<http::Response<LogsResponseBody>, LogsError>> + Send>>
44 {
45 Box::pin(async move { Err(LogsError::not_implemented(op.as_str())) })
46 }
47}