Struct rocket::Route [] [src]

pub struct Route {
    pub method: Method,
    pub handler: Handler,
    pub base: URI<'static>,
    pub uri: URI<'static>,
    pub rank: isize,
    pub format: Option<MediaType>,
}

A route: a method, its handler, path, rank, and format/media type.

Fields

The method this route matches against.

The function that should be called when the route matches.

The base mount point of this Route.

The uri (in Rocket format) that should be matched against. This uri already includes the base mount point.

The rank of this route. Lower ranks have higher priorities.

The media type this route matches against, if any.

Methods

impl Route
[src]

[src]

Creates a new route with the given method, path, and handler with a base of /.

Ranking

The route rank's is set so that routes with static paths are ranked higher than route's with dynamic paths, and routes with query strings are ranked higher than ranks without query strings. This default ranking is summarized by the table below:

static path query rank
yes yes -4
yes no -3
no yes -2
no no -1

Example

use rocket::{Request, Route, Data};
use rocket::handler::Outcome;
use rocket::http::Method;

fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> {
    Outcome::from(request, "Hello, world!")
}

// this is a rank -3 route matching requests to `GET /`
let index = Route::new(Method::Get, "/", handler);

// this is a rank -4 route matching requests to `GET /?<name>`
let index_name = Route::new(Method::Get, "/?<name>", handler);

// this is a rank -1 route matching requests to `GET /<name>`
let name = Route::new(Method::Get, "/<name>", handler);

[src]

Creates a new route with the given rank, method, path, and handler with a base of /.

Example

use rocket::{Request, Route, Data};
use rocket::handler::Outcome;
use rocket::http::Method;

fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> {
    Outcome::from(request, "Hello, world!")
}

// this is a rank 1 route matching requests to `GET /`
let index = Route::ranked(1, Method::Get, "/", handler);

[src]

Retrieves the path of the base mount point of this route as an &str.

Example

use rocket::{Request, Route, Data};
use rocket::handler::Outcome;
use rocket::http::Method;

fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> {
    Outcome::from(request, "Hello, world!")
}

let mut index = Route::ranked(1, Method::Get, "/", handler);
assert_eq!(index.base(), "/");
assert_eq!(index.base.path(), "/");

[src]

Sets the base mount point of the route. Does not update the rank or any other parameters.

Example

use rocket::{Request, Route, Data};
use rocket::handler::Outcome;
use rocket::http::Method;

fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> {
    Outcome::from(request, "Hello, world!")
}

let mut index = Route::ranked(1, Method::Get, "/", handler);
assert_eq!(index.base(), "/");
assert_eq!(index.base.path(), "/");

index.set_base("/hi");
assert_eq!(index.base(), "/hi");
assert_eq!(index.base.path(), "/hi");

[src]

Sets the path of the route. Does not update the rank or any other parameters.

Example

use rocket::{Request, Route, Data};
use rocket::handler::Outcome;
use rocket::http::Method;

fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> {
    Outcome::from(request, "Hello, world!")
}

let mut index = Route::ranked(1, Method::Get, "/", handler);
assert_eq!(index.uri.path(), "/");

index.set_uri("/hello");
assert_eq!(index.uri.path(), "/hello");

Trait Implementations

impl<'a, 'r> FromRequest<'a, 'r> for &'r Route
[src]

The associated error to be returned if derivation fails.

[src]

Derives an instance of Self from the incoming request metadata. Read more

impl Clone for Route
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Display for Route
[src]

[src]

Formats the value using the given formatter. Read more

impl Debug for Route
[src]

[src]

Formats the value using the given formatter.