Skip to main content

caelix_core/
controller.rs

1use std::any::Any;
2
3use crate::ProviderDependency;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6/// Public Caelix type `RouteDef`.
7pub struct RouteDef {
8    /// The `method` value.
9    pub method: &'static str,
10    /// The `path` value.
11    pub path: &'static str,
12    /// The `handler` value.
13    pub handler: &'static str,
14}
15
16/// Public Caelix extension trait `Controller`.
17pub trait Controller {
18    /// Public Caelix API.
19    fn base_path() -> &'static str;
20
21    /// Providers resolved by generated route wrappers, such as guards and
22    /// interceptors. These participate in module visibility validation and
23    /// lifecycle ordering just like constructor-injected dependencies.
24    fn route_dependencies() -> Vec<ProviderDependency> {
25        vec![]
26    }
27
28    /// Public Caelix API.
29    fn routes() -> &'static [RouteDef] {
30        &[]
31    }
32    /// Public Caelix API.
33    fn register_routes(cfg: &mut dyn Any);
34
35    #[cfg(feature = "openapi")]
36    #[doc(hidden)]
37    fn openapi_routes() -> &'static [crate::openapi::OpenApiRouteDef] {
38        &[]
39    }
40}