aboutsummaryrefslogtreecommitdiff
path: root/src/handler/response/route.rs
blob: b71e76d6fd4244d53965ba2b74be674bb070398e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use async_trait::async_trait;

use crate::{context::RouteContext, response::Response};

#[allow(clippy::module_name_repetitions)]
#[async_trait]
pub trait RouteResponse: Send + Sync {
  async fn call(&self, context: RouteContext) -> Response;
}

#[async_trait]
impl<T, F> RouteResponse for T
where
  T: Fn(RouteContext) -> F + Send + Sync,
  F: std::future::Future<Output = Response> + Send + 'static,
{
  async fn call(&self, context: RouteContext) -> Response {
    (*self)(context).await
  }
}