pub struct AssociatedRouteBuilder<'a, M, C, P, PE, QSE>where
M: RouteMatcher + Send + Sync + 'static,
C: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,{ /* private fields */ }
Expand description
Implements the methods required for associating a number of routes with a single path. This is
used by DrawRoutes::associated
.
Implementations
sourceimpl<'a, C, P, PE, QSE> AssociatedRouteBuilder<'a, AnyRouteMatcher, C, P, PE, QSE>where
C: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
impl<'a, C, P, PE, QSE> AssociatedRouteBuilder<'a, AnyRouteMatcher, C, P, PE, QSE>where
C: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
sourcepub fn new(
node_builder: &'a mut Node,
pipeline_chain: C,
pipelines: PipelineSet<P>
) -> Self
pub fn new(
node_builder: &'a mut Node,
pipeline_chain: C,
pipelines: PipelineSet<P>
) -> Self
Create an instance of AssociatedRouteBuilder
sourceimpl<'a, M, C, P, PE, QSE> AssociatedRouteBuilder<'a, M, C, P, PE, QSE>where
M: RouteMatcher + Send + Sync + 'static,
C: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
impl<'a, M, C, P, PE, QSE> AssociatedRouteBuilder<'a, M, C, P, PE, QSE>where
M: RouteMatcher + Send + Sync + 'static,
C: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P: RefUnwindSafe + Send + Sync + 'static,
PE: PathExtractor<Body> + Send + Sync + 'static,
QSE: QueryStringExtractor<Body> + Send + Sync + 'static,
sourcepub fn add_route_matcher<'b, NM>(
&'b mut self,
matcher: NM
) -> AssociatedRouteBuilder<'b, AndRouteMatcher<M, NM>, C, P, PE, QSE>where
NM: RouteMatcher + Send + Sync + 'static,
pub fn add_route_matcher<'b, NM>(
&'b mut self,
matcher: NM
) -> AssociatedRouteBuilder<'b, AndRouteMatcher<M, NM>, C, P, PE, QSE>where
NM: RouteMatcher + Send + Sync + 'static,
Adds aadditional RouteMatcher
requirements to all subsequently associated routes.
Examples
build_simple_router(|route| {
let matcher = AcceptHeaderRouteMatcher::new(vec![mime::APPLICATION_JSON]);
route.associate("/resource/path", |assoc| {
let mut assoc = assoc.add_route_matcher(matcher);
assoc.get().to(my_handler);
});
})
sourcepub fn with_path_extractor<'b, NPE>(
&'b mut self
) -> AssociatedRouteBuilder<'b, M, C, P, NPE, QSE>where
NPE: PathExtractor<Body> + Send + Sync + 'static,
pub fn with_path_extractor<'b, NPE>(
&'b mut self
) -> AssociatedRouteBuilder<'b, M, C, P, NPE, QSE>where
NPE: PathExtractor<Body> + Send + Sync + 'static,
Binds a new PathExtractor
to the associated routes.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
#[derive(Deserialize, StateData, StaticResponseExtender)]
struct MyPathExtractor {
id: u32,
}
build_simple_router(|route| {
route.associate("/resource/:id", |assoc| {
let mut assoc = assoc.with_path_extractor::<MyPathExtractor>();
assoc.get().to(handler);
});
})
sourcepub fn with_query_string_extractor<'b, NQSE>(
&'b mut self
) -> AssociatedRouteBuilder<'b, M, C, P, PE, NQSE>where
NQSE: QueryStringExtractor<Body> + Send + Sync + 'static,
pub fn with_query_string_extractor<'b, NQSE>(
&'b mut self
) -> AssociatedRouteBuilder<'b, M, C, P, PE, NQSE>where
NQSE: QueryStringExtractor<Body> + Send + Sync + 'static,
Binds a new QueryStringExtractor
to the associated routes.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
#[derive(StateData, Deserialize, StaticResponseExtender)]
struct MyQueryStringExtractor {
val: String,
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
let mut assoc = assoc.with_query_string_extractor::<MyQueryStringExtractor>();
assoc.get().to(handler);
});
})
sourcepub fn request<'b>(
&'b mut self,
methods: Vec<Method>
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn request<'b>(
&'b mut self,
methods: Vec<Method>
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches requests with any of the specified methods, to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.request(vec![Method::GET, Method::HEAD, Method::POST]).to(handler);
});
})
sourcepub fn head<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn head<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches HEAD
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.head().to(handler);
});
})
sourcepub fn get_or_head<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn get_or_head<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches GET
or HEAD
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.get_or_head().to(handler);
});
})
sourcepub fn get<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn get<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches GET
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.get().to(handler);
});
})
sourcepub fn post<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn post<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches POST
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.post().to(handler);
});
})
sourcepub fn put<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn put<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches PUT
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.put().to(handler);
});
})
sourcepub fn patch<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn patch<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches PATCH
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.patch().to(handler);
});
})
sourcepub fn delete<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn delete<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches DELETE
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.delete().to(handler);
});
})
sourcepub fn options<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
pub fn options<'b>(
&'b mut self
) -> AssociatedSingleRouteBuilder<'b, AndRouteMatcher<MethodOnlyRouteMatcher, M>, C, P, PE, QSE>
Associates a route which matches OPTIONS
requests to the current path.
Examples
fn handler(state: State) -> (State, Response<Body>) {
// Implementation elided.
}
build_simple_router(|route| {
route.associate("/resource", |assoc| {
assoc.options().to(handler);
});
})