sfr_server/handler/
home.rs

1//! The trait representing the interface that returns home page.
2
3use crate::response::home::GetHomeResponse;
4use crate::ResponseError;
5
6/// The trait representing the interface that returns home page.
7pub trait HomeHandlerTrait: Send + Sync {
8    /// Handles the request to get home page.
9    fn handle_home(
10        &self,
11    ) -> impl std::future::Future<Output = Result<Vec<u8>, ResponseError>> + Send;
12}
13
14/// The new type to wrap [`HomeHandlerTrait`].
15#[derive(Clone)]
16pub(crate) struct HomeHandler<T>(T)
17where
18    T: HomeHandlerTrait;
19
20impl<T> HomeHandler<T>
21where
22    T: HomeHandlerTrait,
23{
24    /// The constructor.
25    pub fn new(inner: T) -> Self {
26        Self(inner)
27    }
28
29    /// Handles the request to get home page.
30    pub fn handle<'a>(
31        &'a self,
32    ) -> impl std::future::Future<Output = Result<impl axum::response::IntoResponse, ResponseError>>
33           + Send
34           + 'a {
35        tracing::info!("get home: start to process");
36
37        async move {
38            let resp = self.0.handle_home().await?;
39
40            Ok(GetHomeResponse::new(resp))
41        }
42    }
43}