1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::Handler;

/// Combines two different handlers having the same associated types into a single type.
#[derive(Debug, Clone)]
pub enum Either<L, R> {
    /// First branch of the type.
    Left(L),
    /// Second branch of the type.
    Right(R),
}

#[crate::async_trait]
impl<L, R, I, O> Handler<I> for Either<L, R>
where
    I: Send + 'static,
    L: Handler<I, Output = O>,
    R: Handler<I, Output = O>,
{
    type Output = O;

    async fn call(&self, i: I) -> Self::Output {
        match self {
            Self::Left(l) => l.call(i),
            Self::Right(r) => r.call(i),
        }
        .await
    }
}