use crate::middleware::rpc::RpcServiceT;
use jsonrpsee_types::Request;
#[derive(Clone, Debug)]
pub enum Either<A, B> {
Left(A),
Right(B),
}
impl<S, A, B> tower::Layer<S> for Either<A, B>
where
A: tower::Layer<S>,
B: tower::Layer<S>,
{
type Service = Either<A::Service, B::Service>;
fn layer(&self, inner: S) -> Self::Service {
match self {
Either::Left(layer) => Either::Left(layer.layer(inner)),
Either::Right(layer) => Either::Right(layer.layer(inner)),
}
}
}
impl<'a, A, B> RpcServiceT<'a> for Either<A, B>
where
A: RpcServiceT<'a> + Send + 'a,
B: RpcServiceT<'a> + Send + 'a,
{
type Future = futures_util::future::Either<A::Future, B::Future>;
fn call(&self, request: Request<'a>) -> Self::Future {
match self {
Either::Left(service) => futures_util::future::Either::Left(service.call(request)),
Either::Right(service) => futures_util::future::Either::Right(service.call(request)),
}
}
}