caelix_core/
controller.rs1use std::{any::Any, sync::Arc};
2
3use crate::{Container, ProviderDependency, Result};
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub struct RouteDef {
8 pub method: &'static str,
10 pub path: &'static str,
12 pub handler: &'static str,
14}
15
16pub trait Controller {
18 fn base_path() -> &'static str;
20
21 fn route_dependencies() -> Vec<ProviderDependency> {
25 vec![]
26 }
27
28 #[doc(hidden)]
30 fn validate_routes() -> Result<()> {
31 Ok(())
32 }
33
34 fn routes() -> &'static [RouteDef] {
36 &[]
37 }
38 fn register_routes(cfg: &mut dyn Any);
40
41 #[doc(hidden)]
43 fn register_routes_with_container(cfg: &mut dyn Any, _container: Arc<Container>) {
44 Self::register_routes(cfg);
45 }
46
47 #[cfg(feature = "openapi")]
48 #[doc(hidden)]
49 fn openapi_routes() -> &'static [crate::openapi::OpenApiRouteDef] {
50 &[]
51 }
52}