quarlus-core 0.1.0

Core runtime for Quarlus web framework - AppBuilder, plugins, guards, and dependency injection
Documentation
/// Construct a controller from the application state alone (no HTTP context).
///
/// Auto-generated by `#[derive(Controller)]` for controllers that do **not**
/// have `#[inject(identity)]` fields. Used internally by consumer and
/// scheduled-task code paths.
#[diagnostic::on_unimplemented(
    message = "`{Self}` cannot be constructed from state alone",
    note = "controllers with #[inject(identity)] fields require an HTTP context"
)]
pub trait StatefulConstruct<S> {
    fn from_state(state: &S) -> Self;
}

pub trait Controller<T: Clone + Send + Sync + 'static> {
    fn routes() -> crate::http::Router<T>;

    /// Return metadata about all routes registered by this controller.
    /// Used for OpenAPI spec generation. Default returns an empty list.
    fn route_metadata() -> Vec<crate::openapi::RouteInfo> {
        Vec::new()
    }

    /// Register event consumers for this controller.
    ///
    /// Called during `serve()` with the application state, before startup hooks.
    /// The default implementation does nothing.
    fn register_consumers(
        _state: T,
    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send>> {
        Box::pin(async {})
    }

    /// Return scheduled task definitions declared via `#[scheduled]`.
    ///
    /// Called by `register_controller()` to collect tasks automatically.
    /// The default implementation returns an empty list.
    fn scheduled_tasks() -> Vec<crate::scheduling::ScheduledTaskDef<T>> {
        Vec::new()
    }
}