viz_core/handler/
and_then.rs

1use crate::{Handler, Result};
2
3/// Calls `op` if the output is `Ok`, otherwise returns the `Err` value of the output.
4#[derive(Debug, Clone)]
5pub struct AndThen<H, F> {
6    h: H,
7    f: F,
8}
9
10impl<H, F> AndThen<H, F> {
11    /// Creates an [`AndThen`] 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> Handler<I> for AndThen<H, F>
20where
21    I: Send + 'static,
22    H: Handler<I, Output = Result<O>>,
23    F: Handler<O, Output = H::Output>,
24    O: Send,
25{
26    type Output = F::Output;
27
28    async fn call(&self, i: I) -> Self::Output {
29        self.f.call(self.h.call(i).await?).await
30    }
31}