1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// 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()
}
}