aboutsummaryrefslogtreecommitdiff
path: root/src/handler/response/error.rs
blob: 8303f25f3f57907a134deedbaeef64c90583cf83 (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::ErrorContext, response::Response};

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

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