use hyper::Body;
use std::panic::RefUnwindSafe;
use crate::extractor::{PathExtractor, QueryStringExtractor};
use crate::pipeline::PipelineHandleChain;
use crate::router::builder::single::DefineSingleRoute;
use crate::router::builder::SingleRouteBuilder;
use crate::router::route::matcher::{AndRouteMatcher, RouteMatcher};
pub trait ReplacePathExtractor<T>
where
T: PathExtractor<Body>,
{
type Output: DefineSingleRoute;
#[doc(hidden)]
fn replace_path_extractor(self) -> Self::Output;
}
impl<'a, M, C, P, PE, QSE, NPE> ReplacePathExtractor<NPE>
for SingleRouteBuilder<'a, M, C, P, PE, QSE>
where
M: RouteMatcher + Send + Sync + 'static,
C: PipelineHandleChain<P> + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
NPE: PathExtractor<Body> + Send + Sync + 'static,
{
type Output = SingleRouteBuilder<'a, M, C, P, NPE, QSE>;
fn replace_path_extractor(self) -> Self::Output {
self.coerce()
}
}
pub trait ReplaceQueryStringExtractor<T>
where
T: QueryStringExtractor<Body>,
{
type Output: DefineSingleRoute;
#[doc(hidden)]
fn replace_query_string_extractor(self) -> Self::Output;
}
impl<'a, M, C, P, PE, QSE, NQSE> ReplaceQueryStringExtractor<NQSE>
for SingleRouteBuilder<'a, M, C, P, PE, QSE>
where
M: RouteMatcher + Send + Sync + 'static,
C: PipelineHandleChain<P> + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
NQSE: QueryStringExtractor<Body> + Send + Sync + 'static,
{
type Output = SingleRouteBuilder<'a, M, C, P, PE, NQSE>;
fn replace_query_string_extractor(self) -> Self::Output {
self.coerce()
}
}
pub trait ExtendRouteMatcher<NRM>
where
NRM: RouteMatcher + Send + Sync + 'static,
{
type Output: DefineSingleRoute;
#[doc(hidden)]
fn extend_route_matcher(self, matcher: NRM) -> Self::Output;
}
impl<'a, M, NRM, C, P, PE, QSE> ExtendRouteMatcher<NRM> for SingleRouteBuilder<'a, M, C, P, PE, QSE>
where
M: RouteMatcher + Send + Sync + 'static,
NRM: RouteMatcher + Send + Sync + 'static,
C: PipelineHandleChain<P> + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
{
type Output = SingleRouteBuilder<'a, AndRouteMatcher<M, NRM>, C, P, PE, QSE>;
fn extend_route_matcher(self, matcher: NRM) -> Self::Output {
SingleRouteBuilder {
matcher: AndRouteMatcher::<M, NRM>::new(self.matcher, matcher),
phantom: self.phantom,
node_builder: self.node_builder,
pipeline_chain: self.pipeline_chain,
pipelines: self.pipelines,
}
}
}