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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::;
use Method;
use ;
/// A type-erased, method-specific endpoint handler.
///
/// `MethodHandler` is the internal representation used by the router after
/// request extraction and routing have completed.
///
/// It accepts a fully-formed [`Request`] and shared state `S`, and produces
/// a [`Flow`] that always resolves to a concrete [`Response`].
///
/// This indirection allows heterogeneous endpoint handlers to be stored
/// in a single routing table.
pub type MethodHandler<S> = dyn Fn + Send
+ Sync
+ 'static;
/// A collection of HTTP method handlers for a single route.
///
/// An [`Endpoint`] corresponds to a matched path. Each HTTP method
/// registered for that path maps to a [`MethodHandler`].
/// A handler for a single routed endpoint.
///
/// `EndpointHandler` is a lower-level abstraction than [`Handler`], used
/// specifically by the router. It represents logic that:
/// - operates on extracted request data (`I`),
/// - has access to shared state `S`,
/// - and produces an output or error convertible into a response.
///
/// Unlike [`Handler`], endpoint handlers return `Result`-like semantics,
/// which are later normalized into [`Flow<Response, Response>`].
///
/// # Type Parameters
///
/// - `I`: Extracted request input
/// - `S`: Shared state type
/// Blanket implementation of [`EndpointHandler`] for async functions and closures.
///
/// Any function or closure with the signature:
///
/// ```text
/// fn(I, S) -> impl Future<Output = Result<O, E>>
/// ```
///
/// automatically implements [`EndpointHandler<I, S>`], as long as both
/// `O` and `E` can be converted into a response.
///
/// This allows endpoint handlers to be written using familiar `Result`
/// semantics, while still integrating with the crate’s [`Flow`]-based
/// control model.