pub trait Route: RefUnwindSafe {
type ResBody;
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
Route
which indicates a match viaRoute::is_match
; - Determine whether the route’s
Delegation
isInternal
orExternal
. IfExternal
, halt processing and dispatch to the innerRouter
; - Run
PathExtractor
andQueryStringExtractor
logic to popuateState
with 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
Determines if this Route
should be invoked, based on the request data in `State.
fn delegation(&self) -> Delegation
fn delegation(&self) -> Delegation
Determines if this Route
intends to delegate requests to a secondary Router
instance.
fn 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
.
fn 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.
fn 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
.
fn 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.