sfr_server/handler/
home.rs

1//! The trait representing the interface that returns home page.
2
3use crate::response::home::GetHomeResponse;
4use crate::ResponseError;
5use axum::async_trait;
6
7/// The trait representing the interface that returns home page.
8#[async_trait]
9pub trait HomeHandlerTrait: Send + Sync {
10    /// Handles the request to get home page.
11    async fn handle_home(&self) -> Result<Vec<u8>, ResponseError>;
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 async fn handle(&self) -> Result<impl axum::response::IntoResponse, ResponseError> {
31        tracing::info!("get home: start to process");
32
33        let resp = self.0.handle_home().await?;
34
35        Ok(GetHomeResponse::new(resp))
36    }
37}