Skip to main content

ControllerSpec

Trait ControllerSpec 

Source
pub trait ControllerSpec {
    // Required method
    fn kind() -> Controller;
}
Expand description

A trait for defining controllers in the application.

Controllers represent different entry points into your application. automatically implement this trait, allowing them to be registered as HTTP controllers within modules.

§Example

use sword::prelude::*;

#[controller(kind = Controller::Web, path = "/api/items")]
struct ItemsController { /* ... */ }

// The macro automatically implements ControllerSpec for ItemsController
// In your module:
fn register_controllers(controllers: &ControllerRegistry) {
    controllers.register::<ItemsController>();
}

Required Methods§

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§