Trait gotham::router::route::Route

source ·
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:

  1. Given a list of routes that match the request path, determine the first Route which indicates a match via Route::is_match;
  2. Determine whether the route’s Delegation is Internal or External. If External, halt processing and dispatch to the inner Router;
  3. Run PathExtractor and QueryStringExtractor logic to popuate State with the necessary request data. If either of these extractors fail, the request is halted here;
  4. 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§

source

type ResBody

The type of the response body. The requirements of Hyper are that this implements HttpBody. Almost always, it will want to be hyper::Body.

Required Methods§

source

fn is_match(&self, state: &State) -> Result<(), RouteNonMatch>

Determines if this Route should be invoked, based on the request data in `State.

source

fn delegation(&self) -> Delegation

Determines if this Route intends to delegate requests to a secondary Router instance.

source

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.

source

fn extend_response_on_path_error( &self, state: &mut State, res: &mut Response<Self::ResBody> )

Extends the Response object when the PathExtractor fails.

source

fn extract_query_string(&self, state: &mut State) -> Result<(), ExtractorFailed>

Extracts the query string parameters and stores the QueryStringExtractor in State.

source

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.

source

fn dispatch(&self, state: State) -> Pin<Box<HandlerFuture>>

Dispatches the request to this Route, which will execute the pipelines and the handler assigned to the `Route.

Implementors§

source§

impl<RM, PE, QSE> Route for RouteImpl<RM, PE, QSE>where RM: RouteMatcher, PE: PathExtractor<Body>, QSE: QueryStringExtractor<Body>,