use crate::std::sync::Arc;
mod dynamic_dispatch;
mod match_service_pair;
mod tuples;
pub use self::{
dynamic_dispatch::{BoxServiceMatcher, DynServiceMatcher},
match_service_pair::MatcherServicePair,
};
#[derive(Debug, Clone)]
pub struct ServiceMatch<Input, Service> {
pub input: Input,
pub service: Option<Service>,
}
pub trait ServiceMatcher<Input>: Send + Sync + 'static {
type Service: Send + 'static;
type Error: Send + 'static;
type ModifiedInput: Send + 'static;
fn match_service(
&self,
input: Input,
) -> impl Future<Output = Result<ServiceMatch<Self::ModifiedInput, Self::Service>, Self::Error>>
+ Send
+ '_;
fn into_match_service(
self,
input: Input,
) -> impl Future<Output = Result<ServiceMatch<Self::ModifiedInput, Self::Service>, Self::Error>> + Send
where
Self: Sized,
Input: Send,
{
async move { self.match_service(input).await }
}
fn boxed(self) -> BoxServiceMatcher<Input, Self::Service, Self::Error, Self::ModifiedInput>
where
Self: Sized,
{
BoxServiceMatcher::new(self)
}
}
impl<Input, M> ServiceMatcher<Input> for Arc<M>
where
M: ServiceMatcher<Input>,
{
type Service = M::Service;
type Error = M::Error;
type ModifiedInput = M::ModifiedInput;
fn match_service(
&self,
input: Input,
) -> impl Future<Output = Result<ServiceMatch<Self::ModifiedInput, Self::Service>, Self::Error>>
+ Send
+ '_ {
(**self).match_service(input)
}
async fn into_match_service(
self,
input: Input,
) -> Result<ServiceMatch<Self::ModifiedInput, Self::Service>, Self::Error>
where
Self: Sized,
Input: Send,
{
(*self).match_service(input).await
}
}