1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::{async_trait, Handler, Request, Response, Result};

/// Alias the boxed Handler.
pub type BoxHandler<I = Request, O = Result<Response>> = Box<dyn Handler<I, Output = O>>;

impl Clone for BoxHandler {
    fn clone(&self) -> Self {
        dyn_clone::clone_box(&**self)
    }
}

#[async_trait]
impl Handler<Request> for BoxHandler {
    type Output = Result<Response>;

    async fn call(&self, req: Request) -> Self::Output {
        self.as_ref().call(req).await
    }
}