pub struct Router { /* private fields */ }Expand description
The route table under declaration.
Implementations§
Source§impl Router
impl Router
Sourcepub fn resource(&mut self, name: &str, controller: Arc<dyn ResourceController>)
pub fn resource(&mut self, name: &str, controller: Arc<dyn ResourceController>)
Register all seven RESTful routes for name.
Sourcepub fn api_resource(
&mut self,
name: &str,
controller: Arc<dyn ResourceController>,
)
pub fn api_resource( &mut self, name: &str, controller: Arc<dyn ResourceController>, )
Register the five API routes for name — everything except the
create and edit form pages.
Sourcepub fn resource_actions(
&mut self,
name: &str,
controller: Arc<dyn ResourceController>,
actions: &[ResourceAction],
)
pub fn resource_actions( &mut self, name: &str, controller: Arc<dyn ResourceController>, actions: &[ResourceAction], )
Register exactly the listed actions.
They are always registered in ResourceAction::ALL order regardless
of the order given, because /posts/create must be declared before
/posts/{post} or the parameter swallows it.
Source§impl Router
impl Router
Sourcepub fn add<H, Args>(
&mut self,
methods: Vec<Method>,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn add<H, Args>(
&mut self,
methods: Vec<Method>,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
Register a route for methods, returning it for further configuration.
Sourcepub fn add_erased(
&mut self,
methods: Vec<Method>,
uri: impl Into<String>,
handler: Arc<dyn RouteHandler>,
) -> &mut Route
pub fn add_erased( &mut self, methods: Vec<Method>, uri: impl Into<String>, handler: Arc<dyn RouteHandler>, ) -> &mut Route
Register a route from an already-erased handler.
The path resource routes and other generated routes take, where the handler was built dynamically rather than inferred from a function signature.
Sourcepub fn get<H, Args>(&mut self, uri: impl Into<String>, handler: H) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn get<H, Args>(&mut self, uri: impl Into<String>, handler: H) -> &mut Routewhere
H: IntoRouteHandler<Args>,
GET (and HEAD).
Sourcepub fn post<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn post<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
POST.
Sourcepub fn put<H, Args>(&mut self, uri: impl Into<String>, handler: H) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn put<H, Args>(&mut self, uri: impl Into<String>, handler: H) -> &mut Routewhere
H: IntoRouteHandler<Args>,
PUT.
Sourcepub fn patch<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn patch<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
PATCH.
Sourcepub fn delete<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn delete<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
DELETE.
Sourcepub fn options<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn options<H, Args>(
&mut self,
uri: impl Into<String>,
handler: H,
) -> &mut Routewhere
H: IntoRouteHandler<Args>,
OPTIONS.
Sourcepub fn any<H, Args>(&mut self, uri: impl Into<String>, handler: H) -> &mut Routewhere
H: IntoRouteHandler<Args>,
pub fn any<H, Args>(&mut self, uri: impl Into<String>, handler: H) -> &mut Routewhere
H: IntoRouteHandler<Args>,
Every common method.
Sourcepub fn redirect(
&mut self,
from: impl Into<String>,
to: impl Into<String>,
) -> &mut Route
pub fn redirect( &mut self, from: impl Into<String>, to: impl Into<String>, ) -> &mut Route
A permanent redirect from from to to.
Sourcepub fn fallback<H, Args>(&mut self, handler: H)where
H: IntoRouteHandler<Args>,
pub fn fallback<H, Args>(&mut self, handler: H)where
H: IntoRouteHandler<Args>,
The handler for requests that match nothing.
Without one, an unmatched request is a plain 404.
Sourcepub fn group(
&mut self,
attributes: GroupAttributes,
declare: impl FnOnce(&mut Router),
)
pub fn group( &mut self, attributes: GroupAttributes, declare: impl FnOnce(&mut Router), )
Declare routes that share a prefix, a name prefix, middleware, or parameter constraints.
Groups nest: the attributes are applied to every route the closure added, after any inner group has applied its own — so the outer prefix ends up outermost and the outer middleware runs first.
Sourcepub fn merge(&mut self, other: Router)
pub fn merge(&mut self, other: Router)
Merge another router’s routes into this one, keeping their order.
Sourcepub fn routes_mut(&mut self) -> &mut [Route]
pub fn routes_mut(&mut self) -> &mut [Route]
Mutable access to the declared routes.
Sourcepub fn named_routes(&self) -> Vec<(&str, &str)>
pub fn named_routes(&self) -> Vec<(&str, &str)>
Every named route, as (name, uri).
Sourcepub fn describe(&self) -> Vec<RouteSummary>
pub fn describe(&self) -> Vec<RouteSummary>
The route table, without compiling anything.
CompiledRouter::describe needs a container, because compiling
builds every middleware stage — and a deferred stage that resolves a
service will fail if that service is not bound. That is the right
behaviour before serving traffic and the wrong behaviour for a question
as harmless as “what routes are there?”.
So route:list, a documentation generator and a test asserting on the
table can all ask here. The middleware column is the declared
labels, which is what those callers wanted to read anyway.
Sourcepub fn compile(self, container: &Container) -> Result<CompiledRouter, Error>
pub fn compile(self, container: &Container) -> Result<CompiledRouter, Error>
Build every route’s pipeline.
Takes no registry: a route holds its middleware, so there is nothing to look up. It takes the container, because this is where every deferred stage is built — the point in the lifecycle where the container is populated and no request has arrived yet.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Router
impl !UnwindSafe for Router
impl Freeze for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl UnsafeUnpin for Router
Blanket Implementations§
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> 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