pub struct Router { /* private fields */ }Implementations§
Source§impl Router
impl Router
pub fn new() -> Self
Sourcepub fn route<H: Handler>(
&mut self,
method: Method,
path: &str,
handler: H,
) -> &mut Self
pub fn route<H: Handler>( &mut self, method: Method, path: &str, handler: H, ) -> &mut Self
§Panics
If the pattern has a glob segment anywhere but last. Routes are drawn once at boot, so this surfaces immediately.
Sourcepub fn constrain(&mut self, param: &str, pattern: &str) -> &mut Self
pub fn constrain(&mut self, param: &str, pattern: &str) -> &mut Self
Requires the last route’s param to match pattern in full, as
Rails’ constraints: {platform: /ios|android/}; otherwise the route
doesn’t match (routes!: where platform = "ios|android").
§Panics
If no route was added yet, or the pattern isn’t a valid regex.
pub fn get(&mut self, path: &str, handler: impl Handler) -> &mut Self
pub fn post(&mut self, path: &str, handler: impl Handler) -> &mut Self
pub fn put(&mut self, path: &str, handler: impl Handler) -> &mut Self
pub fn patch(&mut self, path: &str, handler: impl Handler) -> &mut Self
pub fn delete(&mut self, path: &str, handler: impl Handler) -> &mut Self
Sourcepub fn scope(
&mut self,
prefix: &str,
draw: impl FnOnce(&mut Router),
) -> &mut Self
pub fn scope( &mut self, prefix: &str, draw: impl FnOnce(&mut Router), ) -> &mut Self
Groups routes under a common path prefix.
Sourcepub fn pipe_through(
&mut self,
pipeline: &Pipeline,
draw: impl FnOnce(&mut Router),
) -> &mut Self
pub fn pipe_through( &mut self, pipeline: &Pipeline, draw: impl FnOnce(&mut Router), ) -> &mut Self
Runs every route drawn inside draw through pipeline’s middleware.
Pipelines nest: inner routes run outer pipelines first.
Unlike app-level middleware, pipelines run after routing, so they don’t see 404s.
Sourcepub fn version(
&mut self,
name: &str,
default: bool,
draw: impl FnOnce(&mut Router),
) -> &mut Self
pub fn version( &mut self, name: &str, default: bool, draw: impl FnOnce(&mut Router), ) -> &mut Self
Routes that answer only requests for API version name (an
Api-Version: 2 header, or Accept: application/vnd.app.v2+json),
as GitHub’s API versions. The default version also answers
requests that name none. routes!: scope "/" version "2" { … }.
Sourcepub fn document<C: Documented>(&mut self) -> &mut Self
pub fn document<C: Documented>(&mut self) -> &mut Self
Records what C’s actions respond with, for OpenAPI. routes!
does this for every controller it routes to.
Sourcepub fn resources<R: Resource>(&mut self, name: &str) -> &mut Self
pub fn resources<R: Resource>(&mut self, name: &str) -> &mut Self
Mounts R’s RESTful actions under /name: all seven by default, or
exactly those defined in a #[glacier::controller].
Sourcepub fn resources_only<R: Resource>(
&mut self,
name: &str,
actions: &[Action],
) -> &mut Self
pub fn resources_only<R: Resource>( &mut self, name: &str, actions: &[Action], ) -> &mut Self
Mounts only the given actions of R under /name.
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> 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