Struct gotham::router::route::RouteImpl
[−]
[src]
pub struct RouteImpl<RM, RE, QSE> where
RM: RouteMatcher,
RE: PathExtractor,
QSE: QueryStringExtractor, { /* fields omitted */ }
Default implementation for Route
.
Examples
Standard Route
which calls application code
fn handler(state: State, _req: Request) -> (State, Response) { let res = create_response(&state, StatusCode::Ok, None); (state, res) } let pipeline_set = finalize_pipeline_set(new_pipeline_set()); let methods = vec![Method::Get]; let matcher = MethodOnlyRouteMatcher::new(methods); let dispatcher = Box::new(DispatcherImpl::new(|| Ok(handler), (), pipeline_set)); let extractors: Extractors<NoopPathExtractor, NoopQueryStringExtractor> = Extractors::new(); RouteImpl::new(matcher, dispatcher, extractors, Delegation::Internal);
A Route
which delegates remaining Request
details to a secondary Router
instance
fn handler(state: State, _req: Request) -> (State, Response) { let res = create_response(&state, StatusCode::Ok, None); (state, res) } let secondary_router = { let pipeline_set = finalize_pipeline_set(new_pipeline_set()); let mut tree_builder = TreeBuilder::new(); let route = { let methods = vec![Method::Get]; let matcher = MethodOnlyRouteMatcher::new(methods); let dispatcher = Box::new(DispatcherImpl::new(|| Ok(handler), (), pipeline_set)); let extractors: Extractors<NoopPathExtractor, NoopQueryStringExtractor> = Extractors::new(); let route = RouteImpl::new(matcher, dispatcher, extractors, Delegation::Internal); Box::new(route) }; tree_builder.add_route(route); let tree = tree_builder.finalize(); Router::new(tree, ResponseFinalizerBuilder::new().finalize()) }; let pipeline_set = finalize_pipeline_set(new_pipeline_set()); let methods = vec![Method::Get]; let matcher = MethodOnlyRouteMatcher::new(methods); let dispatcher = Box::new(DispatcherImpl::new(secondary_router, (), pipeline_set)); let extractors: Extractors<NoopPathExtractor, NoopQueryStringExtractor> = Extractors::new(); RouteImpl::new(matcher, dispatcher, extractors, Delegation::External);
Methods
impl<RM, RE, QSE> RouteImpl<RM, RE, QSE> where
RM: RouteMatcher,
RE: PathExtractor,
QSE: QueryStringExtractor,
[src]
RM: RouteMatcher,
RE: PathExtractor,
QSE: QueryStringExtractor,
fn new(
matcher: RM,
dispatcher: Box<Dispatcher + Send + Sync>,
_extractors: Extractors<RE, QSE>,
delegation: Delegation
) -> Self
matcher: RM,
dispatcher: Box<Dispatcher + Send + Sync>,
_extractors: Extractors<RE, QSE>,
delegation: Delegation
) -> Self
Creates a new RouteImpl
Trait Implementations
impl<RM, RE, QSE> Route for RouteImpl<RM, RE, QSE> where
RM: RouteMatcher,
RE: PathExtractor,
QSE: QueryStringExtractor,
[src]
RM: RouteMatcher,
RE: PathExtractor,
QSE: QueryStringExtractor,
fn is_match(&self, state: &State, req: &Request) -> Result<(), StatusCode>
Determines if this Route
can be invoked, based on the Request
.
fn delegation(&self) -> Delegation
Determines if this Route
intends to delegate requests to a secondary Router
instance.
fn dispatch(&self, state: State, req: Request) -> Box<HandlerFuture>
Final call made by the Router
to the matched Route
allowing application specific logic to respond to the request. Read more
fn extract_request_path(
&self,
state: &mut State,
segment_mapping: SegmentMapping
) -> Result<(), String>
&self,
state: &mut State,
segment_mapping: SegmentMapping
) -> Result<(), String>
Extracts the Request
path and stores it in State
fn extend_response_on_path_error(&self, state: &mut State, res: &mut Response)
Extends the Response
object when path extraction fails
fn extract_query_string(
&self,
state: &mut State,
query: Option<&str>
) -> Result<(), String>
&self,
state: &mut State,
query: Option<&str>
) -> Result<(), String>
Extracts the Request
query string and stores it in State
fn extend_response_on_query_string_error(
&self,
state: &mut State,
res: &mut Response
)
&self,
state: &mut State,
res: &mut Response
)
Extends the Response
object when query string extraction fails