pub struct Router { /* private fields */ }Expand description
A request router: match by method and path, dispatch to a handler.
See the module docs for the pattern syntax and an example. Build one
with Router::new, add routes with the per-method builders (or the generic
route), and optionally set a fallback
for unmatched paths. The result implements Handler.
Implementations§
Source§impl Router
impl Router
Sourcepub fn route<H>(self, method: Method, pattern: &str, handler: H) -> Routerwhere
H: RouteHandler + 'static,
pub fn route<H>(self, method: Method, pattern: &str, handler: H) -> Routerwhere
H: RouteHandler + 'static,
Register handler for method requests matching pattern.
Sourcepub fn get<H: RouteHandler + 'static>(self, pattern: &str, handler: H) -> Router
pub fn get<H: RouteHandler + 'static>(self, pattern: &str, handler: H) -> Router
Register a GET route.
Sourcepub fn post<H: RouteHandler + 'static>(
self,
pattern: &str,
handler: H,
) -> Router
pub fn post<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router
Register a POST route.
Sourcepub fn put<H: RouteHandler + 'static>(self, pattern: &str, handler: H) -> Router
pub fn put<H: RouteHandler + 'static>(self, pattern: &str, handler: H) -> Router
Register a PUT route.
Sourcepub fn delete<H: RouteHandler + 'static>(
self,
pattern: &str,
handler: H,
) -> Router
pub fn delete<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router
Register a DELETE route.
Sourcepub fn patch<H: RouteHandler + 'static>(
self,
pattern: &str,
handler: H,
) -> Router
pub fn patch<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router
Register a PATCH route.
Sourcepub fn head<H: RouteHandler + 'static>(
self,
pattern: &str,
handler: H,
) -> Router
pub fn head<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router
Register a HEAD route.
Sourcepub fn options<H: RouteHandler + 'static>(
self,
pattern: &str,
handler: H,
) -> Router
pub fn options<H: RouteHandler + 'static>( self, pattern: &str, handler: H, ) -> Router
Register an OPTIONS route.
Sourcepub fn fallback<H: RouteHandler + 'static>(self, handler: H) -> Router
pub fn fallback<H: RouteHandler + 'static>(self, handler: H) -> Router
Set the handler invoked when no route matches the path (otherwise 404).
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
Mutably borrows from an owned value. Read more