Skip to main content

Controller

Trait Controller 

Source
pub trait Controller: Sized + 'static {
    type State: Send + Sync + 'static;

    // Required method
    fn mount(
        state: Arc<Self::State>,
    ) -> impl FnOnce(Router<()>) -> Result<Router<()>>;
}
Expand description

A pure descriptor for a group of HTTP routes sharing a common service dependency.

Do not implement this trait manually. Use the [mount_handlers!] macro, which generates the correct Kleisli arrow from your handler list.

The trait’s only concern is: given Arc<State>, produce a Kleisli arrow that registers this controller’s routes into a Router<()>.

Required Associated Types§

Source

type State: Send + Sync + 'static

The service this controller depends on.

The framework wraps it in Arc<State>Clone is not required on the service itself. Use Atomic* primitives or channels for any state that changes after construction.

Required Methods§

Source

fn mount( state: Arc<Self::State>, ) -> impl FnOnce(Router<()>) -> Result<Router<()>>

Returns the Kleisli arrow for this controller.

Signature: Arc<State> -> (Router<()> -> Result<Router<()>>)

Generated by mount_handlers!. The returned closure:

  1. Builds a scoped Router<Arc<State>> with this controller’s routes.
  2. Provides state via .with_state(state)Router<()>.
  3. Merges into the outer router and returns Ok(merged).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§