pub struct Route { /* private fields */ }Expand description
A declared route.
Implementations§
Source§impl Route
impl Route
Sourcepub fn new(
methods: Vec<Method>,
uri: impl Into<String>,
handler: Arc<dyn RouteHandler>,
) -> Route
pub fn new( methods: Vec<Method>, uri: impl Into<String>, handler: Arc<dyn RouteHandler>, ) -> Route
A route for methods at uri, served by handler.
HEAD is added alongside GET automatically, as every HTTP server is
expected to answer a HEAD wherever it answers a GET.
Sourcepub fn name(&mut self, name: impl Into<String>) -> &mut Route
pub fn name(&mut self, name: impl Into<String>) -> &mut Route
Name the route, so it can be resolved into a URL.
Sourcepub fn middleware(&mut self, middleware: impl IntoMiddlewareStack) -> &mut Route
pub fn middleware(&mut self, middleware: impl IntoMiddlewareStack) -> &mut Route
Attach middleware.
Takes the middleware itself — one instance, a tuple of them, or a
whole MiddlewareStack from a group function. There is no name to
misspell and no registry to look anything up in.
router.post("/login", login)
.middleware(ThrottleRequests::per_minute(10));
router.get("/admin", dashboard)
.middleware((Authenticate::new(auth), RequireRole::Admin));
router.get("/", home).middleware(kernel::web());Sourcepub fn without_middleware<M>(&mut self) -> &mut Routewhere
M: Middleware,
pub fn without_middleware<M>(&mut self) -> &mut Routewhere
M: Middleware,
Skip a middleware this route would otherwise inherit from its group.
By type, because that is the only identity a value has:
router.post("/webhooks/stripe", stripe)
.without_middleware::<VerifyCsrfToken>();Matches the concrete type, so excluding ThrottleRequests removes
every rate limiter the group applied, not one particular configuration
of it. Where that is too blunt, do not put it in the group.
Sourcepub fn where_param(
&mut self,
param: impl Into<String>,
constraint: ParamConstraint,
) -> &mut Route
pub fn where_param( &mut self, param: impl Into<String>, constraint: ParamConstraint, ) -> &mut Route
Constrain a route parameter.
Sourcepub fn where_number(&mut self, param: impl Into<String>) -> &mut Route
pub fn where_number(&mut self, param: impl Into<String>) -> &mut Route
Constrain a parameter to digits.
Sourcepub fn where_slug(&mut self, param: impl Into<String>) -> &mut Route
pub fn where_slug(&mut self, param: impl Into<String>) -> &mut Route
Constrain a parameter to a slug.
Sourcepub fn where_uuid(&mut self, param: impl Into<String>) -> &mut Route
pub fn where_uuid(&mut self, param: impl Into<String>) -> &mut Route
Constrain a parameter to a UUID.
Sourcepub fn where_in(
&mut self,
param: impl Into<String>,
values: impl IntoIterator<Item = impl Into<String>>,
) -> &mut Route
pub fn where_in( &mut self, param: impl Into<String>, values: impl IntoIterator<Item = impl Into<String>>, ) -> &mut Route
Constrain a parameter to a fixed set of values.
Sourcepub fn route_name(&self) -> Option<&str>
pub fn route_name(&self) -> Option<&str>
The route’s name, if it has one.
Sourcepub fn middleware_stack(&self) -> &MiddlewareStack
pub fn middleware_stack(&self) -> &MiddlewareStack
The middleware attached to this route, outermost first.
Sourcepub fn excluded_middleware(&self) -> &[TypeId]
pub fn excluded_middleware(&self) -> &[TypeId]
The types this route opts out of.
Sourcepub fn handler(&self) -> &Arc<dyn RouteHandler> ⓘ
pub fn handler(&self) -> &Arc<dyn RouteHandler> ⓘ
The handler.
Sourcepub fn param_names(&self) -> Vec<&str>
pub fn param_names(&self) -> Vec<&str>
The parameter names this route captures, in order.
Sourcepub fn match_path(&self, path: &str) -> Option<HashMap<String, String>>
pub fn match_path(&self, path: &str) -> Option<HashMap<String, String>>
Match path against this route’s pattern, returning the captured
parameters. None if the shape differs or a constraint rejects a value.
Sourcepub fn matches_path_only(&self, path: &str) -> bool
pub fn matches_path_only(&self, path: &str) -> bool
Whether path matches, ignoring the method — used to answer 405
instead of 404 when a route exists but not for this method.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Route
impl !UnwindSafe for Route
impl Freeze for Route
impl Send for Route
impl Sync for Route
impl Unpin for Route
impl UnsafeUnpin for Route
Blanket Implementations§
impl<T> Actor for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more