pub struct Router { /* private fields */ }Expand description
A modular router for grouping related routes and applying scoped middleware.
Router allows you to build sub-sections of your application (e.g., an /api or /auth module)
and mount them to the main App later. Middleware added to a Router only executes for
routes defined within that router.
§Example
ⓘ
let mut app = App::new();
let api = Router::new();
app.mount("/api", api)Implementations§
Source§impl Router
impl Router
pub fn new() -> Self
pub fn use_middleware<M: Middleware + 'static>(&mut self, mw: M)
pub fn route<M: Middleware + 'static>( &mut self, method: Method, path: impl Into<Cow<'static, str>>, mw: M, )
Sourcepub fn get<M: Middleware + 'static>(
&mut self,
path: impl Into<String>,
middleware: M,
)
pub fn get<M: Middleware + 'static>( &mut self, path: impl Into<String>, middleware: M, )
Adds a route to the application for the HTTP method.
Sourcepub fn post<M: Middleware + 'static>(
&mut self,
path: impl Into<String>,
middleware: M,
)
pub fn post<M: Middleware + 'static>( &mut self, path: impl Into<String>, middleware: M, )
Adds a route to the application for the HTTP method.
Sourcepub fn put<M: Middleware + 'static>(
&mut self,
path: impl Into<String>,
middleware: M,
)
pub fn put<M: Middleware + 'static>( &mut self, path: impl Into<String>, middleware: M, )
Adds a route to the application for the HTTP method.
Sourcepub fn delete<M: Middleware + 'static>(
&mut self,
path: impl Into<String>,
middleware: M,
)
pub fn delete<M: Middleware + 'static>( &mut self, path: impl Into<String>, middleware: M, )
Adds a route to the application for the HTTP method.
Sourcepub fn patch<M: Middleware + 'static>(
&mut self,
path: impl Into<String>,
middleware: M,
)
pub fn patch<M: Middleware + 'static>( &mut self, path: impl Into<String>, middleware: M, )
Adds a route to the application for the HTTP method.
Sourcepub fn head<M: Middleware + 'static>(
&mut self,
path: impl Into<String>,
middleware: M,
)
pub fn head<M: Middleware + 'static>( &mut self, path: impl Into<String>, middleware: M, )
Adds a route to the application for the HTTP method.
Sourcepub fn options<M: Middleware + 'static>(
&mut self,
path: impl Into<String>,
middleware: M,
)
pub fn options<M: Middleware + 'static>( &mut self, path: impl Into<String>, middleware: M, )
Adds a route to the application for the HTTP method.
Auto Trait Implementations§
impl Freeze for Router
impl !RefUnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl !UnwindSafe 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