viz_core/handler/
either.rs

1use crate::Handler;
2
3/// Combines two different handlers having the same associated types into a single type.
4#[derive(Clone, Debug)]
5pub enum Either<L, R> {
6    /// First branch of the type.
7    Left(L),
8    /// Second branch of the type.
9    Right(R),
10}
11
12#[crate::async_trait]
13impl<L, R, I, O> Handler<I> for Either<L, R>
14where
15    I: Send + 'static,
16    L: Handler<I, Output = O>,
17    R: Handler<I, Output = O>,
18{
19    type Output = O;
20
21    async fn call(&self, i: I) -> Self::Output {
22        match self {
23            Self::Left(l) => l.call(i),
24            Self::Right(r) => r.call(i),
25        }
26        .await
27    }
28}