viz_core/handler/
map.rs

1use crate::{Handler, Result};
2
3/// Maps the `Ok` value of the output if after the handler called.
4#[derive(Debug, Clone)]
5pub struct Map<H, F> {
6    h: H,
7    f: F,
8}
9
10impl<H, F> Map<H, F> {
11    /// Creates a [`Map`] handler.
12    #[inline]
13    pub const fn new(h: H, f: F) -> Self {
14        Self { h, f }
15    }
16}
17
18#[crate::async_trait]
19impl<H, F, I, O, T> Handler<I> for Map<H, F>
20where
21    I: Send + 'static,
22    H: Handler<I, Output = Result<O>>,
23    F: FnOnce(O) -> T + Send + Sync + Copy + 'static,
24{
25    type Output = Result<T>;
26
27    async fn call(&self, i: I) -> Self::Output {
28        self.h.call(i).await.map(self.f)
29    }
30}