pub struct GroupDef { /* private fields */ }Expand description
Group definition that collects routes and applies prefix/middleware
Supports nested groups for arbitrary route organization:
routes! {
group!("/api", {
get!("/users", controllers::user::index).name("api.users"),
post!("/users", controllers::user::store),
// Nested groups are supported
group!("/admin", {
get!("/dashboard", controllers::admin::dashboard),
}),
}).middleware(AuthMiddleware),
}Implementations§
Source§impl GroupDef
impl GroupDef
Sourcepub fn add<I: IntoGroupItem>(self, item: I) -> Self
pub fn add<I: IntoGroupItem>(self, item: I) -> Self
Add an item (route or nested group) to this group
This is the primary method for adding items to a group. It accepts
anything that implements IntoGroupItem, including routes created
with get!, post!, etc., and nested groups created with group!.
Sourcepub fn route<H, Fut>(self, route: RouteDefBuilder<H>) -> Self
pub fn route<H, Fut>(self, route: RouteDefBuilder<H>) -> Self
Add a route to this group (backward compatibility)
Prefer using .add() which accepts both routes and nested groups.
Sourcepub fn middleware<M: Middleware + 'static>(self, middleware: M) -> Self
pub fn middleware<M: Middleware + 'static>(self, middleware: M) -> Self
Sourcepub fn register(self, router: Router) -> Router
pub fn register(self, router: Router) -> Router
Register all routes in this group with the router
This prepends the group prefix to each route path and applies group middleware to all routes. Nested groups are flattened recursively, with prefixes concatenated and middleware inherited from parent groups.
§Path Combination
- If route path is “/” (root), the full path is just the group prefix
- Otherwise, prefix and route path are concatenated
§Middleware Inheritance
Parent group middleware is applied before child group middleware, which is applied before route-specific middleware.
Trait Implementations§
Source§impl IntoGroupItem for GroupDef
impl IntoGroupItem for GroupDef
fn into_group_item(self) -> GroupItem
Auto Trait Implementations§
impl Freeze for GroupDef
impl !RefUnwindSafe for GroupDef
impl Send for GroupDef
impl Sync for GroupDef
impl Unpin for GroupDef
impl UnsafeUnpin for GroupDef
impl !UnwindSafe for GroupDef
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
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