gotham/router/builder/
modify.rs1use hyper::Body;
2
3use std::panic::RefUnwindSafe;
4
5use crate::extractor::{PathExtractor, QueryStringExtractor};
6use crate::pipeline::PipelineHandleChain;
7use crate::router::builder::single::DefineSingleRoute;
8use crate::router::builder::SingleRouteBuilder;
9use crate::router::route::matcher::{AndRouteMatcher, RouteMatcher};
10
11pub trait ReplacePathExtractor<T>
14where
15 T: PathExtractor<Body>,
16{
17 type Output: DefineSingleRoute;
19
20 #[doc(hidden)]
21 fn replace_path_extractor(self) -> Self::Output;
24}
25
26impl<'a, M, C, P, PE, QSE, NPE> ReplacePathExtractor<NPE>
27 for SingleRouteBuilder<'a, M, C, P, PE, QSE>
28where
29 M: RouteMatcher + Send + Sync + 'static,
30 C: PipelineHandleChain<P> + Send + Sync + 'static,
31 P: RefUnwindSafe + Send + Sync + 'static,
32 PE: PathExtractor<Body> + Send + Sync + 'static,
33 QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
34 NPE: PathExtractor<Body> + Send + Sync + 'static,
35{
36 type Output = SingleRouteBuilder<'a, M, C, P, NPE, QSE>;
37
38 fn replace_path_extractor(self) -> Self::Output {
39 self.coerce()
40 }
41}
42
43pub trait ReplaceQueryStringExtractor<T>
46where
47 T: QueryStringExtractor<Body>,
48{
49 type Output: DefineSingleRoute;
51
52 #[doc(hidden)]
53 fn replace_query_string_extractor(self) -> Self::Output;
56}
57
58impl<'a, M, C, P, PE, QSE, NQSE> ReplaceQueryStringExtractor<NQSE>
59 for SingleRouteBuilder<'a, M, C, P, PE, QSE>
60where
61 M: RouteMatcher + Send + Sync + 'static,
62 C: PipelineHandleChain<P> + Send + Sync + 'static,
63 P: RefUnwindSafe + Send + Sync + 'static,
64 PE: PathExtractor<Body> + Send + Sync + 'static,
65 QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
66 NQSE: QueryStringExtractor<Body> + Send + Sync + 'static,
67{
68 type Output = SingleRouteBuilder<'a, M, C, P, PE, NQSE>;
69
70 fn replace_query_string_extractor(self) -> Self::Output {
71 self.coerce()
72 }
73}
74
75pub trait ExtendRouteMatcher<NRM>
78where
79 NRM: RouteMatcher + Send + Sync + 'static,
80{
81 type Output: DefineSingleRoute;
83
84 #[doc(hidden)]
85 fn extend_route_matcher(self, matcher: NRM) -> Self::Output;
88}
89
90impl<'a, M, NRM, C, P, PE, QSE> ExtendRouteMatcher<NRM> for SingleRouteBuilder<'a, M, C, P, PE, QSE>
91where
92 M: RouteMatcher + Send + Sync + 'static,
93 NRM: RouteMatcher + Send + Sync + 'static,
94 C: PipelineHandleChain<P> + Send + Sync + 'static,
95 P: RefUnwindSafe + Send + Sync + 'static,
96 PE: PathExtractor<Body> + Send + Sync + 'static,
97 QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
98{
99 type Output = SingleRouteBuilder<'a, AndRouteMatcher<M, NRM>, C, P, PE, QSE>;
101
102 fn extend_route_matcher(self, matcher: NRM) -> Self::Output {
103 SingleRouteBuilder {
104 matcher: AndRouteMatcher::<M, NRM>::new(self.matcher, matcher),
105 phantom: self.phantom,
106 node_builder: self.node_builder,
107 pipeline_chain: self.pipeline_chain,
108 pipelines: self.pipelines,
109 }
110 }
111}