viz_core/handler/
around.rs

1use crate::{Handler, Result};
2
3/// Represents a middleware parameter, which is a tuple that includes Requset and `BoxHandler`.
4pub type Next<I, H> = (I, H);
5
6/// Wraps around the remaining handler or middleware chain.
7#[derive(Debug, Clone)]
8pub struct Around<H, F> {
9    h: H,
10    f: F,
11}
12
13impl<H, F> Around<H, F> {
14    /// Creates an [`Around`] handler.
15    #[inline]
16    pub const fn new(h: H, f: F) -> Self {
17        Self { h, f }
18    }
19}
20
21#[crate::async_trait]
22impl<H, F, I, O> Handler<I> for Around<H, F>
23where
24    I: Send + 'static,
25    H: Handler<I, Output = Result<O>> + Clone,
26    F: Handler<Next<I, H>, Output = H::Output>,
27{
28    type Output = F::Output;
29
30    async fn call(&self, i: I) -> Self::Output {
31        self.f.call((i, self.h.clone())).await
32    }
33}