Skip to main content

Controller

Trait Controller 

Source
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 from AppState. Panics with a clear message at startup if a dependency is missing.
  • register — returns an OxideRouter with all route methods registered. Methods that take &self are wrapped in closures that capture Arc<Self>.

Required Associated Constants§

Source

const PREFIX: &'static str

URL prefix for all routes in this controller (e.g. "/api/users").

Required Methods§

Source

fn from_state(state: &AppState) -> Self

Construct the controller from application state.

Source

fn register(self: Arc<Self>) -> OxideRouter

Register all route methods on a fresh router.

Provided Methods§

Source

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.

Implementors§