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
use crate::{async_trait, 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),
}
#[async_trait]
impl<L, R, I, O> Handler<I> for Either<L, R>
where
    I: Send + 'static,
    L: Handler<I, Output = O> + Clone,
    R: Handler<I, Output = O> + Clone,
{
    type Output = O;
    async fn call(&self, i: I) -> Self::Output {
        match self {
            Self::Left(l) => l.call(i).await,
            Self::Right(r) => r.call(i).await,
        }
    }
}