pub trait Controller:
Send
+ Sync
+ Sized
+ 'static {
const PREFIX: &'static str;
// Required methods
fn from_state(state: &AppState) -> Self;
fn register(self: Arc<Self>) -> OxideRouter;
// Provided method
fn configure_router(router: Router) -> Router { ... }
}Expand description
Trait implemented by #[controller]-annotated types.
You don’t implement this manually — the #[controller("/prefix")] macro
generates the implementation for you.
§Generated methods
from_state— constructs the controller, extracting dependencies fromAppState. Panics with a clear message at startup if a dependency is missing.register— returns anOxideRouterwith all route methods registered. Methods that take&selfare wrapped in closures that captureArc<Self>.
Required Associated Constants§
Required Methods§
Sourcefn from_state(state: &AppState) -> Self
fn from_state(state: &AppState) -> Self
Construct the controller from application state.
Sourcefn register(self: Arc<Self>) -> OxideRouter
fn register(self: Arc<Self>) -> OxideRouter
Register all route methods on a fresh router.
Provided Methods§
Sourcefn configure_router(router: Router) -> Router
fn configure_router(router: Router) -> Router
Override to apply controller-scoped middleware (auth, logging, etc.).
The router passed in already contains all of this controller’s routes. Return the router with additional layers applied. The default is a no-op (no extra middleware).
If the #[controller] macro finds a fn middleware(router: Router) -> Router
method in the impl block, it generates this override automatically.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.