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]

Creates a new RouteImpl

Trait Implementations

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

Determines if this Route can be invoked, based on the Request.

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

Final call made by the Router to the matched Route allowing application specific logic to respond to the request. Read more

Extracts the Request path and stores it in State

Extends the Response object when path extraction fails

Extracts the Request query string and stores it in State

Extends the Response object when query string extraction fails