pub trait Route: RefUnwindSafe {
type ResBody;
// Required methods
fn is_match(&self, state: &State) -> Result<(), RouteNonMatch>;
fn delegation(&self) -> Delegation;
fn extract_request_path<'a>(
&self,
state: &mut State,
params: SegmentMapping<'a>,
) -> Result<(), ExtractorFailed>;
fn extend_response_on_path_error(
&self,
state: &mut State,
res: &mut Response<Self::ResBody>,
);
fn extract_query_string(
&self,
state: &mut State,
) -> Result<(), ExtractorFailed>;
fn extend_response_on_query_string_error(
&self,
state: &mut State,
res: &mut Response<Self::ResBody>,
);
fn dispatch(&self, state: State) -> Pin<Box<HandlerFuture>>;
}Expand description
Values of the Route type are used by the Router to conditionally dispatch a request after
matching the path segments successfully. The steps taken in dispatching to a Route are:
- Given a list of routes that match the request path, determine the first
Routewhich indicates a match viaRoute::is_match; - Determine whether the route’s
DelegationisInternalorExternal. IfExternal, halt processing and dispatch to the innerRouter; - Run
PathExtractorandQueryStringExtractorlogic to popuateStatewith the necessary request data. If either of these extractors fail, the request is halted here; - Dispatch the request via
Route::dispatch.
Route exists as a trait to allow abstraction over the generic types in RouteImpl. This
trait should not be implemented outside of Gotham.
Required Associated Types§
Required Methods§
Sourcefn is_match(&self, state: &State) -> Result<(), RouteNonMatch>
fn is_match(&self, state: &State) -> Result<(), RouteNonMatch>
Determines if this Route should be invoked, based on the request data in `State.
Sourcefn delegation(&self) -> Delegation
fn delegation(&self) -> Delegation
Determines if this Route intends to delegate requests to a secondary Router instance.
Sourcefn extract_request_path<'a>(
&self,
state: &mut State,
params: SegmentMapping<'a>,
) -> Result<(), ExtractorFailed>
fn extract_request_path<'a>( &self, state: &mut State, params: SegmentMapping<'a>, ) -> Result<(), ExtractorFailed>
Extracts dynamic components of the Request path and stores the PathExtractor in State.
Sourcefn extend_response_on_path_error(
&self,
state: &mut State,
res: &mut Response<Self::ResBody>,
)
fn extend_response_on_path_error( &self, state: &mut State, res: &mut Response<Self::ResBody>, )
Extends the Response object when the PathExtractor fails.
Sourcefn extract_query_string(&self, state: &mut State) -> Result<(), ExtractorFailed>
fn extract_query_string(&self, state: &mut State) -> Result<(), ExtractorFailed>
Extracts the query string parameters and stores the QueryStringExtractor in State.
Sourcefn extend_response_on_query_string_error(
&self,
state: &mut State,
res: &mut Response<Self::ResBody>,
)
fn extend_response_on_query_string_error( &self, state: &mut State, res: &mut Response<Self::ResBody>, )
Extends the Response object when query string extraction fails.