A route: a method, its handler, path, rank, and format/media type.
The method this route matches against.
handler: Handler
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.
Creates a new route with the given method, path, and handler with a base
of /
.
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 |
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 index = Route::new(Method::Get, "/", handler);
let index_name = Route::new(Method::Get, "/?<name>", handler);
let name = Route::new(Method::Get, "/<name>", handler);
Creates a new route with the given rank, method, path, and handler with
a base of /
.
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 index = Route::ranked(1, Method::Get, "/", handler);
Retrieves the path of the base mount point of this route as an &str
.
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(), "/");
Sets the base mount point of the route. Does not update the rank or any
other parameters.
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");
Sets the path of the route. Does not update the rank or any other
parameters.
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");
The associated error to be returned if derivation fails.
Derives an instance of Self
from the incoming request metadata. Read more
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts the given value to a String
. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
impl<T> Typeable for T where T: Any, | |
Get the TypeId
of this object.