pub struct Router { /* private fields */ }Implementations§
Source§impl Router
impl Router
pub fn new() -> Self
Sourcepub fn middleware<M: Middleware>(&mut self, middleware: M) -> &mut Self
pub fn middleware<M: Middleware>(&mut self, middleware: M) -> &mut Self
Attach middleware to every route in this router (and its groups).
pub fn get<A: Action>(&mut self, path: &str, action: A) -> &mut Route
pub fn post<A: Action>(&mut self, path: &str, action: A) -> &mut Route
pub fn put<A: Action>(&mut self, path: &str, action: A) -> &mut Route
pub fn patch<A: Action>(&mut self, path: &str, action: A) -> &mut Route
pub fn delete<A: Action>(&mut self, path: &str, action: A) -> &mut Route
Sourcepub fn options<A: Action>(&mut self, path: &str, action: A) -> &mut Route
pub fn options<A: Action>(&mut self, path: &str, action: A) -> &mut Route
Register an OPTIONS route, typically a CORS preflight responder.
Sourcepub fn resource<C: ResourceRoutes>(
&mut self,
path: &str,
controller: C,
) -> &mut Router
pub fn resource<C: ResourceRoutes>( &mut self, path: &str, controller: C, ) -> &mut Router
Register a controller’s resource actions under path.
ⓘ
r.resource("/posts", PostsController).middleware(Auth::jwt());Returns the group the routes live in, so middleware attaches to all of them at once.
Sourcepub fn group(
&mut self,
prefix: &str,
build: impl FnOnce(&mut Router),
) -> &mut Self
pub fn group( &mut self, prefix: &str, build: impl FnOnce(&mut Router), ) -> &mut Self
Nest routes under a shared prefix. Call r.middleware(..) inside the
closure to apply middleware to the whole group.
Sourcepub fn static_files(&mut self, path: &str, dir: &str) -> &mut Self
pub fn static_files(&mut self, path: &str, dir: &str) -> &mut Self
Serve dir from the filesystem under path.
ⓘ
r.static_files("/build", "public/build");Used for a built frontend bundle. In development the Vite dev server serves those files instead, so this route is simply unused.
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