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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Controller trait — pure descriptor for composable route groups.
//!
//! A `Controller` is a zero-knowledge marker type. It knows only two things:
//! 1. `type State` — the service it needs (`Arc<State>` is resolved and
//! passed in)
//! 2. `fn mount` — a Kleisli arrow `Arc<State> -> (Router -> Result<Router>)`
//!
//! Controllers have **no dependency on `Router`, `RouteSet`, or any DI
//! container**. The `mount_handlers!` macro generates the `mount`
//! implementation from a simple list of `(route_constant, handler_fn)` pairs.
//! Users only write handlers.
//!
//! # Kleisli Composition
//!
//! `mount` returns `impl FnOnce(Router<()>) -> Result<Router<()>>` — a Kleisli
//! arrow in the `Result` monad. The `RouterPipeline` composes these arrows with
//! `and_then` (`>>=`), threading the router through each controller in
//! sequence. A failed arrow short-circuits the rest.
//!
//! # Immutability Contract
//!
//! State is passed as `Arc<S>` — shared, immutable after construction. Services
//! must not expose `&mut self` methods. All state mutation goes through
//! `Atomic*` primitives or channels (never `Mutex<T>` on the service struct).
//!
//! # Example
//!
//! ```ignore
//! pub struct HealthController;
//!
//! #[get("/health")]
//! pub async fn health_check(State(svc): State<Arc<HealthService>>) -> Json<HealthResponse> {
//! Json(svc.health_check())
//! }
//!
//! // mount_handlers! generates the full Controller impl — user never writes Router.
//! mount_handlers!(HealthController, HealthService, [
//! (__health_check_route, health_check),
//! ]);
//! ```
use Arc;
use crate::;
/// A pure descriptor for a group of HTTP routes sharing a common service
/// dependency.
///
/// Do not implement this trait manually. Use the [`mount_handlers!`] macro,
/// which generates the correct Kleisli arrow from your handler list.
///
/// The trait's only concern is: given `Arc<State>`, produce a Kleisli arrow
/// that registers this controller's routes into a `Router<()>`.