viz_core/handler/
into_handler.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::{handler::FnExtHandler, FnExt, FromRequest, Handler, IntoResponse, Result};

/// The trait implemented by types that can be converted to a [`Handler`].
pub trait IntoHandler<I, E> {
    /// The target handler.
    type Handler: Handler<I>;

    /// Converts self to a [`Handler`].
    #[must_use]
    fn into_handler(self) -> Self::Handler;
}

impl<I, H, E, O> IntoHandler<I, E> for H
where
    I: Send + 'static,
    E: FromRequest + 'static,
    E::Error: IntoResponse,
    H: FnExt<I, E, Output = Result<O>>,
    O: 'static,
{
    type Handler = FnExtHandler<H, E, O>;

    fn into_handler(self) -> Self::Handler {
        FnExtHandler::new(self)
    }
}