[][src]Trait gotham::router::route::Route

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) -> Box<HandlerFuture>; }

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.

Associated Types

type ResBody

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

Loading content...

Required methods

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

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

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>

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>
)

Extends the Response object when the PathExtractor fails.

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>
)

Extends the Response object when query string extraction fails.

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

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

Loading content...

Implementors

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

type ResBody = Body

Loading content...