viz_core/handler/
into_handler.rs

1use crate::{FnExt, FromRequest, Handler, IntoResponse, Result, handler::FnExtHandler};
2
3/// The trait implemented by types that can be converted to a [`Handler`].
4pub trait IntoHandler<I, E> {
5    /// The target handler.
6    type Handler: Handler<I>;
7
8    /// Converts self to a [`Handler`].
9    #[must_use]
10    fn into_handler(self) -> Self::Handler;
11}
12
13impl<I, H, E, O> IntoHandler<I, E> for H
14where
15    I: Send + 'static,
16    E: FromRequest + 'static,
17    E::Error: IntoResponse,
18    H: FnExt<I, E, Output = Result<O>>,
19    O: 'static,
20{
21    type Handler = FnExtHandler<H, E, O>;
22
23    fn into_handler(self) -> Self::Handler {
24        FnExtHandler::new(self)
25    }
26}