sfr-server 0.1.2

The server implementation for a Slack App.
Documentation
//! The trait representing the interface that returns home page.

use crate::response::home::GetHomeResponse;
use crate::ResponseError;

/// The trait representing the interface that returns home page.
pub trait HomeHandlerTrait: Send + Sync {
    /// Handles the request to get home page.
    fn handle_home(
        &self,
    ) -> impl std::future::Future<Output = Result<Vec<u8>, ResponseError>> + Send;
}

/// The new type to wrap [`HomeHandlerTrait`].
#[derive(Clone)]
pub(crate) struct HomeHandler<T>(T)
where
    T: HomeHandlerTrait;

impl<T> HomeHandler<T>
where
    T: HomeHandlerTrait,
{
    /// The constructor.
    pub fn new(inner: T) -> Self {
        Self(inner)
    }

    /// Handles the request to get home page.
    pub fn handle<'a>(
        &'a self,
    ) -> impl std::future::Future<Output = Result<impl axum::response::IntoResponse, ResponseError>>
           + Send
           + 'a {
        tracing::info!("get home: start to process");

        async move {
            let resp = self.0.handle_home().await?;

            Ok(GetHomeResponse::new(resp))
        }
    }
}