spikard 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +659 -659
  4. data/ext/spikard_rb/Cargo.toml +17 -17
  5. data/ext/spikard_rb/extconf.rb +10 -10
  6. data/ext/spikard_rb/src/lib.rs +6 -6
  7. data/lib/spikard/app.rb +386 -386
  8. data/lib/spikard/background.rb +27 -27
  9. data/lib/spikard/config.rb +396 -396
  10. data/lib/spikard/converters.rb +13 -13
  11. data/lib/spikard/handler_wrapper.rb +113 -113
  12. data/lib/spikard/provide.rb +214 -214
  13. data/lib/spikard/response.rb +173 -173
  14. data/lib/spikard/schema.rb +243 -243
  15. data/lib/spikard/sse.rb +111 -111
  16. data/lib/spikard/streaming_response.rb +44 -44
  17. data/lib/spikard/testing.rb +221 -221
  18. data/lib/spikard/upload_file.rb +131 -131
  19. data/lib/spikard/version.rb +5 -5
  20. data/lib/spikard/websocket.rb +59 -59
  21. data/lib/spikard.rb +43 -43
  22. data/sig/spikard.rbs +366 -360
  23. data/vendor/crates/spikard-core/Cargo.toml +40 -40
  24. data/vendor/crates/spikard-core/src/bindings/mod.rs +3 -3
  25. data/vendor/crates/spikard-core/src/bindings/response.rs +133 -133
  26. data/vendor/crates/spikard-core/src/debug.rs +63 -63
  27. data/vendor/crates/spikard-core/src/di/container.rs +726 -726
  28. data/vendor/crates/spikard-core/src/di/dependency.rs +273 -273
  29. data/vendor/crates/spikard-core/src/di/error.rs +118 -118
  30. data/vendor/crates/spikard-core/src/di/factory.rs +538 -538
  31. data/vendor/crates/spikard-core/src/di/graph.rs +545 -545
  32. data/vendor/crates/spikard-core/src/di/mod.rs +192 -192
  33. data/vendor/crates/spikard-core/src/di/resolved.rs +411 -411
  34. data/vendor/crates/spikard-core/src/di/value.rs +283 -283
  35. data/vendor/crates/spikard-core/src/errors.rs +39 -39
  36. data/vendor/crates/spikard-core/src/http.rs +153 -153
  37. data/vendor/crates/spikard-core/src/lib.rs +29 -29
  38. data/vendor/crates/spikard-core/src/lifecycle.rs +422 -422
  39. data/vendor/crates/spikard-core/src/parameters.rs +722 -722
  40. data/vendor/crates/spikard-core/src/problem.rs +310 -310
  41. data/vendor/crates/spikard-core/src/request_data.rs +189 -189
  42. data/vendor/crates/spikard-core/src/router.rs +249 -249
  43. data/vendor/crates/spikard-core/src/schema_registry.rs +183 -183
  44. data/vendor/crates/spikard-core/src/type_hints.rs +304 -304
  45. data/vendor/crates/spikard-core/src/validation.rs +699 -699
  46. data/vendor/crates/spikard-http/Cargo.toml +68 -58
  47. data/vendor/crates/spikard-http/src/auth.rs +247 -247
  48. data/vendor/crates/spikard-http/src/background.rs +249 -249
  49. data/vendor/crates/spikard-http/src/bindings/mod.rs +3 -3
  50. data/vendor/crates/spikard-http/src/bindings/response.rs +1 -1
  51. data/vendor/crates/spikard-http/src/body_metadata.rs +8 -8
  52. data/vendor/crates/spikard-http/src/cors.rs +490 -490
  53. data/vendor/crates/spikard-http/src/debug.rs +63 -63
  54. data/vendor/crates/spikard-http/src/di_handler.rs +423 -423
  55. data/vendor/crates/spikard-http/src/handler_response.rs +190 -190
  56. data/vendor/crates/spikard-http/src/handler_trait.rs +228 -228
  57. data/vendor/crates/spikard-http/src/handler_trait_tests.rs +284 -284
  58. data/vendor/crates/spikard-http/src/lib.rs +529 -529
  59. data/vendor/crates/spikard-http/src/lifecycle/adapter.rs +149 -149
  60. data/vendor/crates/spikard-http/src/lifecycle.rs +428 -428
  61. data/vendor/crates/spikard-http/src/middleware/mod.rs +285 -285
  62. data/vendor/crates/spikard-http/src/middleware/multipart.rs +86 -86
  63. data/vendor/crates/spikard-http/src/middleware/urlencoded.rs +147 -147
  64. data/vendor/crates/spikard-http/src/middleware/validation.rs +287 -287
  65. data/vendor/crates/spikard-http/src/openapi/mod.rs +309 -309
  66. data/vendor/crates/spikard-http/src/openapi/parameter_extraction.rs +190 -190
  67. data/vendor/crates/spikard-http/src/openapi/schema_conversion.rs +308 -308
  68. data/vendor/crates/spikard-http/src/openapi/spec_generation.rs +195 -195
  69. data/vendor/crates/spikard-http/src/parameters.rs +1 -1
  70. data/vendor/crates/spikard-http/src/problem.rs +1 -1
  71. data/vendor/crates/spikard-http/src/query_parser.rs +369 -369
  72. data/vendor/crates/spikard-http/src/response.rs +399 -399
  73. data/vendor/crates/spikard-http/src/router.rs +1 -1
  74. data/vendor/crates/spikard-http/src/schema_registry.rs +1 -1
  75. data/vendor/crates/spikard-http/src/server/handler.rs +87 -87
  76. data/vendor/crates/spikard-http/src/server/lifecycle_execution.rs +98 -98
  77. data/vendor/crates/spikard-http/src/server/mod.rs +805 -805
  78. data/vendor/crates/spikard-http/src/server/request_extraction.rs +119 -119
  79. data/vendor/crates/spikard-http/src/sse.rs +447 -447
  80. data/vendor/crates/spikard-http/src/testing/form.rs +14 -14
  81. data/vendor/crates/spikard-http/src/testing/multipart.rs +60 -60
  82. data/vendor/crates/spikard-http/src/testing/test_client.rs +285 -285
  83. data/vendor/crates/spikard-http/src/testing.rs +377 -377
  84. data/vendor/crates/spikard-http/src/type_hints.rs +1 -1
  85. data/vendor/crates/spikard-http/src/validation.rs +1 -1
  86. data/vendor/crates/spikard-http/src/websocket.rs +324 -324
  87. data/vendor/crates/spikard-rb/Cargo.toml +42 -42
  88. data/vendor/crates/spikard-rb/build.rs +8 -8
  89. data/vendor/crates/spikard-rb/src/background.rs +63 -63
  90. data/vendor/crates/spikard-rb/src/config.rs +294 -294
  91. data/vendor/crates/spikard-rb/src/conversion.rs +453 -453
  92. data/vendor/crates/spikard-rb/src/di.rs +409 -409
  93. data/vendor/crates/spikard-rb/src/handler.rs +625 -625
  94. data/vendor/crates/spikard-rb/src/lib.rs +2771 -2771
  95. data/vendor/crates/spikard-rb/src/lifecycle.rs +274 -274
  96. data/vendor/crates/spikard-rb/src/server.rs +283 -283
  97. data/vendor/crates/spikard-rb/src/sse.rs +231 -231
  98. data/vendor/crates/spikard-rb/src/test_client.rs +404 -404
  99. data/vendor/crates/spikard-rb/src/test_sse.rs +143 -143
  100. data/vendor/crates/spikard-rb/src/test_websocket.rs +221 -221
  101. data/vendor/crates/spikard-rb/src/websocket.rs +233 -233
  102. metadata +1 -79
  103. data/vendor/spikard-core/Cargo.toml +0 -40
  104. data/vendor/spikard-core/src/bindings/mod.rs +0 -3
  105. data/vendor/spikard-core/src/bindings/response.rs +0 -133
  106. data/vendor/spikard-core/src/debug.rs +0 -63
  107. data/vendor/spikard-core/src/di/container.rs +0 -726
  108. data/vendor/spikard-core/src/di/dependency.rs +0 -273
  109. data/vendor/spikard-core/src/di/error.rs +0 -118
  110. data/vendor/spikard-core/src/di/factory.rs +0 -538
  111. data/vendor/spikard-core/src/di/graph.rs +0 -545
  112. data/vendor/spikard-core/src/di/mod.rs +0 -192
  113. data/vendor/spikard-core/src/di/resolved.rs +0 -411
  114. data/vendor/spikard-core/src/di/value.rs +0 -283
  115. data/vendor/spikard-core/src/http.rs +0 -153
  116. data/vendor/spikard-core/src/lib.rs +0 -28
  117. data/vendor/spikard-core/src/lifecycle.rs +0 -422
  118. data/vendor/spikard-core/src/parameters.rs +0 -719
  119. data/vendor/spikard-core/src/problem.rs +0 -310
  120. data/vendor/spikard-core/src/request_data.rs +0 -189
  121. data/vendor/spikard-core/src/router.rs +0 -249
  122. data/vendor/spikard-core/src/schema_registry.rs +0 -183
  123. data/vendor/spikard-core/src/type_hints.rs +0 -304
  124. data/vendor/spikard-core/src/validation.rs +0 -699
  125. data/vendor/spikard-http/Cargo.toml +0 -58
  126. data/vendor/spikard-http/src/auth.rs +0 -247
  127. data/vendor/spikard-http/src/background.rs +0 -249
  128. data/vendor/spikard-http/src/bindings/mod.rs +0 -3
  129. data/vendor/spikard-http/src/bindings/response.rs +0 -1
  130. data/vendor/spikard-http/src/body_metadata.rs +0 -8
  131. data/vendor/spikard-http/src/cors.rs +0 -490
  132. data/vendor/spikard-http/src/debug.rs +0 -63
  133. data/vendor/spikard-http/src/di_handler.rs +0 -423
  134. data/vendor/spikard-http/src/handler_response.rs +0 -190
  135. data/vendor/spikard-http/src/handler_trait.rs +0 -228
  136. data/vendor/spikard-http/src/handler_trait_tests.rs +0 -284
  137. data/vendor/spikard-http/src/lib.rs +0 -529
  138. data/vendor/spikard-http/src/lifecycle/adapter.rs +0 -149
  139. data/vendor/spikard-http/src/lifecycle.rs +0 -428
  140. data/vendor/spikard-http/src/middleware/mod.rs +0 -285
  141. data/vendor/spikard-http/src/middleware/multipart.rs +0 -86
  142. data/vendor/spikard-http/src/middleware/urlencoded.rs +0 -147
  143. data/vendor/spikard-http/src/middleware/validation.rs +0 -287
  144. data/vendor/spikard-http/src/openapi/mod.rs +0 -309
  145. data/vendor/spikard-http/src/openapi/parameter_extraction.rs +0 -190
  146. data/vendor/spikard-http/src/openapi/schema_conversion.rs +0 -308
  147. data/vendor/spikard-http/src/openapi/spec_generation.rs +0 -195
  148. data/vendor/spikard-http/src/parameters.rs +0 -1
  149. data/vendor/spikard-http/src/problem.rs +0 -1
  150. data/vendor/spikard-http/src/query_parser.rs +0 -369
  151. data/vendor/spikard-http/src/response.rs +0 -399
  152. data/vendor/spikard-http/src/router.rs +0 -1
  153. data/vendor/spikard-http/src/schema_registry.rs +0 -1
  154. data/vendor/spikard-http/src/server/handler.rs +0 -80
  155. data/vendor/spikard-http/src/server/lifecycle_execution.rs +0 -98
  156. data/vendor/spikard-http/src/server/mod.rs +0 -805
  157. data/vendor/spikard-http/src/server/request_extraction.rs +0 -119
  158. data/vendor/spikard-http/src/sse.rs +0 -447
  159. data/vendor/spikard-http/src/testing/form.rs +0 -14
  160. data/vendor/spikard-http/src/testing/multipart.rs +0 -60
  161. data/vendor/spikard-http/src/testing/test_client.rs +0 -285
  162. data/vendor/spikard-http/src/testing.rs +0 -377
  163. data/vendor/spikard-http/src/type_hints.rs +0 -1
  164. data/vendor/spikard-http/src/validation.rs +0 -1
  165. data/vendor/spikard-http/src/websocket.rs +0 -324
  166. data/vendor/spikard-rb/Cargo.toml +0 -42
  167. data/vendor/spikard-rb/build.rs +0 -8
  168. data/vendor/spikard-rb/src/background.rs +0 -63
  169. data/vendor/spikard-rb/src/config.rs +0 -294
  170. data/vendor/spikard-rb/src/conversion.rs +0 -392
  171. data/vendor/spikard-rb/src/di.rs +0 -409
  172. data/vendor/spikard-rb/src/handler.rs +0 -534
  173. data/vendor/spikard-rb/src/lib.rs +0 -2020
  174. data/vendor/spikard-rb/src/lifecycle.rs +0 -267
  175. data/vendor/spikard-rb/src/server.rs +0 -283
  176. data/vendor/spikard-rb/src/sse.rs +0 -231
  177. data/vendor/spikard-rb/src/test_client.rs +0 -404
  178. data/vendor/spikard-rb/src/test_sse.rs +0 -143
  179. data/vendor/spikard-rb/src/test_websocket.rs +0 -221
  180. data/vendor/spikard-rb/src/websocket.rs +0 -233
@@ -1,422 +1,422 @@
1
- //! Lifecycle hooks for request/response processing
2
- //!
3
- //! Transport-agnostic lifecycle system shared across HTTP, WASM, and future runtimes.
4
- //! Hooks operate on generic request/response carriers so higher-level crates can
5
- //! plug in their own types without pulling in server frameworks.
6
-
7
- use std::{future::Future, pin::Pin, sync::Arc};
8
-
9
- type RequestHookFutureSend<'a, Req, Resp> =
10
- Pin<Box<dyn Future<Output = Result<HookResult<Req, Resp>, String>> + Send + 'a>>;
11
- type ResponseHookFutureSend<'a, Resp> =
12
- Pin<Box<dyn Future<Output = Result<HookResult<Resp, Resp>, String>> + Send + 'a>>;
13
-
14
- type RequestHookFutureLocal<'a, Req, Resp> = Pin<Box<dyn Future<Output = Result<HookResult<Req, Resp>, String>> + 'a>>;
15
- type ResponseHookFutureLocal<'a, Resp> = Pin<Box<dyn Future<Output = Result<HookResult<Resp, Resp>, String>> + 'a>>;
16
-
17
- /// Result of a lifecycle hook execution
18
- #[derive(Debug)]
19
- pub enum HookResult<T, U> {
20
- /// Continue to the next phase with the (possibly modified) value
21
- Continue(T),
22
- /// Short-circuit the request pipeline and return this response immediately
23
- ShortCircuit(U),
24
- }
25
-
26
- /// Trait for lifecycle hooks on native targets (Send + Sync, Send futures).
27
- pub trait NativeLifecycleHook<Req, Resp>: Send + Sync {
28
- /// Hook name for debugging and error messages
29
- fn name(&self) -> &str;
30
-
31
- /// Execute hook with a request
32
- fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureSend<'a, Req, Resp>;
33
-
34
- /// Execute hook with a response
35
- fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureSend<'a, Resp>;
36
- }
37
-
38
- /// Trait for lifecycle hooks on local (wasm) targets (no Send requirements).
39
- pub trait LocalLifecycleHook<Req, Resp> {
40
- /// Hook name for debugging and error messages
41
- fn name(&self) -> &str;
42
-
43
- /// Execute hook with a request
44
- fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureLocal<'a, Req, Resp>;
45
-
46
- /// Execute hook with a response
47
- fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureLocal<'a, Resp>;
48
- }
49
-
50
- #[cfg(target_arch = "wasm32")]
51
- pub use LocalLifecycleHook as LifecycleHook;
52
- #[cfg(not(target_arch = "wasm32"))]
53
- pub use NativeLifecycleHook as LifecycleHook;
54
-
55
- /// Target-specific hook alias used by the rest of the codebase.
56
- #[cfg(not(target_arch = "wasm32"))]
57
- type CoreHook<Req, Resp> = dyn NativeLifecycleHook<Req, Resp>;
58
- #[cfg(target_arch = "wasm32")]
59
- type CoreHook<Req, Resp> = dyn LocalLifecycleHook<Req, Resp>;
60
-
61
- /// Target-specific container alias to make downstream imports clearer.
62
- pub type TargetLifecycleHooks<Req, Resp> = LifecycleHooks<Req, Resp>;
63
-
64
- /// Container for all lifecycle hooks
65
- #[derive(Clone)]
66
- pub struct LifecycleHooks<Req, Resp> {
67
- on_request: Vec<Arc<CoreHook<Req, Resp>>>,
68
- pre_validation: Vec<Arc<CoreHook<Req, Resp>>>,
69
- pre_handler: Vec<Arc<CoreHook<Req, Resp>>>,
70
- on_response: Vec<Arc<CoreHook<Req, Resp>>>,
71
- on_error: Vec<Arc<CoreHook<Req, Resp>>>,
72
- }
73
-
74
- impl<Req, Resp> Default for LifecycleHooks<Req, Resp> {
75
- fn default() -> Self {
76
- Self {
77
- on_request: Vec::new(),
78
- pre_validation: Vec::new(),
79
- pre_handler: Vec::new(),
80
- on_response: Vec::new(),
81
- on_error: Vec::new(),
82
- }
83
- }
84
- }
85
-
86
- impl<Req, Resp> std::fmt::Debug for LifecycleHooks<Req, Resp> {
87
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88
- f.debug_struct("LifecycleHooks")
89
- .field("on_request_count", &self.on_request.len())
90
- .field("pre_validation_count", &self.pre_validation.len())
91
- .field("pre_handler_count", &self.pre_handler.len())
92
- .field("on_response_count", &self.on_response.len())
93
- .field("on_error_count", &self.on_error.len())
94
- .finish()
95
- }
96
- }
97
-
98
- impl<Req, Resp> LifecycleHooks<Req, Resp> {
99
- /// Create a new empty hooks container
100
- pub fn new() -> Self {
101
- Self::default()
102
- }
103
-
104
- /// Builder constructor for ergonomic hook registration
105
- pub fn builder() -> LifecycleHooksBuilder<Req, Resp> {
106
- LifecycleHooksBuilder::new()
107
- }
108
-
109
- /// Check if any hooks are registered
110
- #[inline(always)]
111
- pub fn is_empty(&self) -> bool {
112
- self.on_request.is_empty()
113
- && self.pre_validation.is_empty()
114
- && self.pre_handler.is_empty()
115
- && self.on_response.is_empty()
116
- && self.on_error.is_empty()
117
- }
118
-
119
- pub fn add_on_request(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
120
- self.on_request.push(hook);
121
- }
122
-
123
- pub fn add_pre_validation(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
124
- self.pre_validation.push(hook);
125
- }
126
-
127
- pub fn add_pre_handler(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
128
- self.pre_handler.push(hook);
129
- }
130
-
131
- pub fn add_on_response(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
132
- self.on_response.push(hook);
133
- }
134
-
135
- pub fn add_on_error(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
136
- self.on_error.push(hook);
137
- }
138
-
139
- pub async fn execute_on_request(&self, mut req: Req) -> Result<HookResult<Req, Resp>, String> {
140
- if self.on_request.is_empty() {
141
- return Ok(HookResult::Continue(req));
142
- }
143
-
144
- for hook in &self.on_request {
145
- match hook.execute_request(req).await? {
146
- HookResult::Continue(r) => req = r,
147
- HookResult::ShortCircuit(response) => return Ok(HookResult::ShortCircuit(response)),
148
- }
149
- }
150
-
151
- Ok(HookResult::Continue(req))
152
- }
153
-
154
- pub async fn execute_pre_validation(&self, mut req: Req) -> Result<HookResult<Req, Resp>, String> {
155
- if self.pre_validation.is_empty() {
156
- return Ok(HookResult::Continue(req));
157
- }
158
-
159
- for hook in &self.pre_validation {
160
- match hook.execute_request(req).await? {
161
- HookResult::Continue(r) => req = r,
162
- HookResult::ShortCircuit(response) => return Ok(HookResult::ShortCircuit(response)),
163
- }
164
- }
165
-
166
- Ok(HookResult::Continue(req))
167
- }
168
-
169
- pub async fn execute_pre_handler(&self, mut req: Req) -> Result<HookResult<Req, Resp>, String> {
170
- if self.pre_handler.is_empty() {
171
- return Ok(HookResult::Continue(req));
172
- }
173
-
174
- for hook in &self.pre_handler {
175
- match hook.execute_request(req).await? {
176
- HookResult::Continue(r) => req = r,
177
- HookResult::ShortCircuit(response) => return Ok(HookResult::ShortCircuit(response)),
178
- }
179
- }
180
-
181
- Ok(HookResult::Continue(req))
182
- }
183
-
184
- pub async fn execute_on_response(&self, mut resp: Resp) -> Result<Resp, String> {
185
- if self.on_response.is_empty() {
186
- return Ok(resp);
187
- }
188
-
189
- for hook in &self.on_response {
190
- match hook.execute_response(resp).await? {
191
- HookResult::Continue(r) => resp = r,
192
- HookResult::ShortCircuit(r) => resp = r,
193
- }
194
- }
195
-
196
- Ok(resp)
197
- }
198
-
199
- pub async fn execute_on_error(&self, mut resp: Resp) -> Result<Resp, String> {
200
- if self.on_error.is_empty() {
201
- return Ok(resp);
202
- }
203
-
204
- for hook in &self.on_error {
205
- match hook.execute_response(resp).await? {
206
- HookResult::Continue(r) => resp = r,
207
- HookResult::ShortCircuit(r) => resp = r,
208
- }
209
- }
210
-
211
- Ok(resp)
212
- }
213
- }
214
-
215
- /// Helper struct for implementing request hooks from closures
216
- struct RequestHookFn<F, Req, Resp> {
217
- name: String,
218
- func: F,
219
- _marker: std::marker::PhantomData<fn(Req, Resp)>,
220
- }
221
-
222
- struct ResponseHookFn<F, Req, Resp> {
223
- name: String,
224
- func: F,
225
- _marker: std::marker::PhantomData<fn(Req, Resp)>,
226
- }
227
-
228
- #[cfg(not(target_arch = "wasm32"))]
229
- impl<F, Fut, Req, Resp> NativeLifecycleHook<Req, Resp> for RequestHookFn<F, Req, Resp>
230
- where
231
- F: Fn(Req) -> Fut + Send + Sync,
232
- Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + Send + 'static,
233
- Req: Send + 'static,
234
- Resp: Send + 'static,
235
- {
236
- fn name(&self) -> &str {
237
- &self.name
238
- }
239
-
240
- fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureSend<'a, Req, Resp> {
241
- Box::pin((self.func)(req))
242
- }
243
-
244
- fn execute_response<'a>(&'a self, _resp: Resp) -> ResponseHookFutureSend<'a, Resp> {
245
- Box::pin(async move { Err("Request hook called with response - this is a bug".to_string()) })
246
- }
247
- }
248
-
249
- #[cfg(target_arch = "wasm32")]
250
- impl<F, Fut, Req, Resp> LocalLifecycleHook<Req, Resp> for RequestHookFn<F, Req, Resp>
251
- where
252
- F: Fn(Req) -> Fut + Send + Sync,
253
- Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + 'static,
254
- Req: 'static,
255
- Resp: 'static,
256
- {
257
- fn name(&self) -> &str {
258
- &self.name
259
- }
260
-
261
- fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureLocal<'a, Req, Resp> {
262
- Box::pin((self.func)(req))
263
- }
264
-
265
- fn execute_response<'a>(&'a self, _resp: Resp) -> ResponseHookFutureLocal<'a, Resp> {
266
- Box::pin(async move { Err("Request hook called with response - this is a bug".to_string()) })
267
- }
268
- }
269
-
270
- #[cfg(not(target_arch = "wasm32"))]
271
- impl<F, Fut, Req, Resp> NativeLifecycleHook<Req, Resp> for ResponseHookFn<F, Req, Resp>
272
- where
273
- F: Fn(Resp) -> Fut + Send + Sync,
274
- Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + Send + 'static,
275
- Req: Send + 'static,
276
- Resp: Send + 'static,
277
- {
278
- fn name(&self) -> &str {
279
- &self.name
280
- }
281
-
282
- fn execute_request<'a>(&'a self, _req: Req) -> RequestHookFutureSend<'a, Req, Resp> {
283
- Box::pin(async move { Err("Response hook called with request - this is a bug".to_string()) })
284
- }
285
-
286
- fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureSend<'a, Resp> {
287
- Box::pin((self.func)(resp))
288
- }
289
- }
290
-
291
- #[cfg(target_arch = "wasm32")]
292
- impl<F, Fut, Req, Resp> LocalLifecycleHook<Req, Resp> for ResponseHookFn<F, Req, Resp>
293
- where
294
- F: Fn(Resp) -> Fut + Send + Sync,
295
- Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + 'static,
296
- Req: 'static,
297
- Resp: 'static,
298
- {
299
- fn name(&self) -> &str {
300
- &self.name
301
- }
302
-
303
- fn execute_request<'a>(&'a self, _req: Req) -> RequestHookFutureLocal<'a, Req, Resp> {
304
- Box::pin(async move { Err("Response hook called with request - this is a bug".to_string()) })
305
- }
306
-
307
- fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureLocal<'a, Resp> {
308
- Box::pin((self.func)(resp))
309
- }
310
- }
311
-
312
- /// Builder Pattern for LifecycleHooks
313
- pub struct LifecycleHooksBuilder<Req, Resp> {
314
- hooks: LifecycleHooks<Req, Resp>,
315
- }
316
-
317
- impl<Req, Resp> LifecycleHooksBuilder<Req, Resp> {
318
- pub fn new() -> Self {
319
- Self {
320
- hooks: LifecycleHooks::default(),
321
- }
322
- }
323
-
324
- pub fn on_request(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
325
- self.hooks.add_on_request(hook);
326
- self
327
- }
328
-
329
- pub fn pre_validation(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
330
- self.hooks.add_pre_validation(hook);
331
- self
332
- }
333
-
334
- pub fn pre_handler(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
335
- self.hooks.add_pre_handler(hook);
336
- self
337
- }
338
-
339
- pub fn on_response(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
340
- self.hooks.add_on_response(hook);
341
- self
342
- }
343
-
344
- pub fn on_error(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
345
- self.hooks.add_on_error(hook);
346
- self
347
- }
348
-
349
- pub fn build(self) -> LifecycleHooks<Req, Resp> {
350
- self.hooks
351
- }
352
- }
353
-
354
- impl<Req, Resp> Default for LifecycleHooksBuilder<Req, Resp> {
355
- fn default() -> Self {
356
- Self::new()
357
- }
358
- }
359
-
360
- /// Create a request hook from an async function or closure (native targets).
361
- #[cfg(not(target_arch = "wasm32"))]
362
- pub fn request_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
363
- where
364
- F: Fn(Req) -> Fut + Send + Sync + 'static,
365
- Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + Send + 'static,
366
- Req: Send + 'static,
367
- Resp: Send + 'static,
368
- {
369
- Arc::new(RequestHookFn {
370
- name: name.into(),
371
- func,
372
- _marker: std::marker::PhantomData,
373
- })
374
- }
375
-
376
- /// Create a request hook from an async function or closure (wasm targets).
377
- #[cfg(target_arch = "wasm32")]
378
- pub fn request_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
379
- where
380
- F: Fn(Req) -> Fut + Send + Sync + 'static,
381
- Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + 'static,
382
- Req: 'static,
383
- Resp: 'static,
384
- {
385
- Arc::new(RequestHookFn {
386
- name: name.into(),
387
- func,
388
- _marker: std::marker::PhantomData,
389
- })
390
- }
391
-
392
- /// Create a response hook from an async function or closure (native targets).
393
- #[cfg(not(target_arch = "wasm32"))]
394
- pub fn response_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
395
- where
396
- F: Fn(Resp) -> Fut + Send + Sync + 'static,
397
- Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + Send + 'static,
398
- Req: Send + 'static,
399
- Resp: Send + 'static,
400
- {
401
- Arc::new(ResponseHookFn {
402
- name: name.into(),
403
- func,
404
- _marker: std::marker::PhantomData,
405
- })
406
- }
407
-
408
- /// Create a response hook from an async function or closure (wasm targets).
409
- #[cfg(target_arch = "wasm32")]
410
- pub fn response_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
411
- where
412
- F: Fn(Resp) -> Fut + Send + Sync + 'static,
413
- Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + 'static,
414
- Req: 'static,
415
- Resp: 'static,
416
- {
417
- Arc::new(ResponseHookFn {
418
- name: name.into(),
419
- func,
420
- _marker: std::marker::PhantomData,
421
- })
422
- }
1
+ //! Lifecycle hooks for request/response processing
2
+ //!
3
+ //! Transport-agnostic lifecycle system shared across HTTP, WASM, and future runtimes.
4
+ //! Hooks operate on generic request/response carriers so higher-level crates can
5
+ //! plug in their own types without pulling in server frameworks.
6
+
7
+ use std::{future::Future, pin::Pin, sync::Arc};
8
+
9
+ type RequestHookFutureSend<'a, Req, Resp> =
10
+ Pin<Box<dyn Future<Output = Result<HookResult<Req, Resp>, String>> + Send + 'a>>;
11
+ type ResponseHookFutureSend<'a, Resp> =
12
+ Pin<Box<dyn Future<Output = Result<HookResult<Resp, Resp>, String>> + Send + 'a>>;
13
+
14
+ type RequestHookFutureLocal<'a, Req, Resp> = Pin<Box<dyn Future<Output = Result<HookResult<Req, Resp>, String>> + 'a>>;
15
+ type ResponseHookFutureLocal<'a, Resp> = Pin<Box<dyn Future<Output = Result<HookResult<Resp, Resp>, String>> + 'a>>;
16
+
17
+ /// Result of a lifecycle hook execution
18
+ #[derive(Debug)]
19
+ pub enum HookResult<T, U> {
20
+ /// Continue to the next phase with the (possibly modified) value
21
+ Continue(T),
22
+ /// Short-circuit the request pipeline and return this response immediately
23
+ ShortCircuit(U),
24
+ }
25
+
26
+ /// Trait for lifecycle hooks on native targets (Send + Sync, Send futures).
27
+ pub trait NativeLifecycleHook<Req, Resp>: Send + Sync {
28
+ /// Hook name for debugging and error messages
29
+ fn name(&self) -> &str;
30
+
31
+ /// Execute hook with a request
32
+ fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureSend<'a, Req, Resp>;
33
+
34
+ /// Execute hook with a response
35
+ fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureSend<'a, Resp>;
36
+ }
37
+
38
+ /// Trait for lifecycle hooks on local (wasm) targets (no Send requirements).
39
+ pub trait LocalLifecycleHook<Req, Resp> {
40
+ /// Hook name for debugging and error messages
41
+ fn name(&self) -> &str;
42
+
43
+ /// Execute hook with a request
44
+ fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureLocal<'a, Req, Resp>;
45
+
46
+ /// Execute hook with a response
47
+ fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureLocal<'a, Resp>;
48
+ }
49
+
50
+ #[cfg(target_arch = "wasm32")]
51
+ pub use LocalLifecycleHook as LifecycleHook;
52
+ #[cfg(not(target_arch = "wasm32"))]
53
+ pub use NativeLifecycleHook as LifecycleHook;
54
+
55
+ /// Target-specific hook alias used by the rest of the codebase.
56
+ #[cfg(not(target_arch = "wasm32"))]
57
+ type CoreHook<Req, Resp> = dyn NativeLifecycleHook<Req, Resp>;
58
+ #[cfg(target_arch = "wasm32")]
59
+ type CoreHook<Req, Resp> = dyn LocalLifecycleHook<Req, Resp>;
60
+
61
+ /// Target-specific container alias to make downstream imports clearer.
62
+ pub type TargetLifecycleHooks<Req, Resp> = LifecycleHooks<Req, Resp>;
63
+
64
+ /// Container for all lifecycle hooks
65
+ #[derive(Clone)]
66
+ pub struct LifecycleHooks<Req, Resp> {
67
+ on_request: Vec<Arc<CoreHook<Req, Resp>>>,
68
+ pre_validation: Vec<Arc<CoreHook<Req, Resp>>>,
69
+ pre_handler: Vec<Arc<CoreHook<Req, Resp>>>,
70
+ on_response: Vec<Arc<CoreHook<Req, Resp>>>,
71
+ on_error: Vec<Arc<CoreHook<Req, Resp>>>,
72
+ }
73
+
74
+ impl<Req, Resp> Default for LifecycleHooks<Req, Resp> {
75
+ fn default() -> Self {
76
+ Self {
77
+ on_request: Vec::new(),
78
+ pre_validation: Vec::new(),
79
+ pre_handler: Vec::new(),
80
+ on_response: Vec::new(),
81
+ on_error: Vec::new(),
82
+ }
83
+ }
84
+ }
85
+
86
+ impl<Req, Resp> std::fmt::Debug for LifecycleHooks<Req, Resp> {
87
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88
+ f.debug_struct("LifecycleHooks")
89
+ .field("on_request_count", &self.on_request.len())
90
+ .field("pre_validation_count", &self.pre_validation.len())
91
+ .field("pre_handler_count", &self.pre_handler.len())
92
+ .field("on_response_count", &self.on_response.len())
93
+ .field("on_error_count", &self.on_error.len())
94
+ .finish()
95
+ }
96
+ }
97
+
98
+ impl<Req, Resp> LifecycleHooks<Req, Resp> {
99
+ /// Create a new empty hooks container
100
+ pub fn new() -> Self {
101
+ Self::default()
102
+ }
103
+
104
+ /// Builder constructor for ergonomic hook registration
105
+ pub fn builder() -> LifecycleHooksBuilder<Req, Resp> {
106
+ LifecycleHooksBuilder::new()
107
+ }
108
+
109
+ /// Check if any hooks are registered
110
+ #[inline(always)]
111
+ pub fn is_empty(&self) -> bool {
112
+ self.on_request.is_empty()
113
+ && self.pre_validation.is_empty()
114
+ && self.pre_handler.is_empty()
115
+ && self.on_response.is_empty()
116
+ && self.on_error.is_empty()
117
+ }
118
+
119
+ pub fn add_on_request(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
120
+ self.on_request.push(hook);
121
+ }
122
+
123
+ pub fn add_pre_validation(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
124
+ self.pre_validation.push(hook);
125
+ }
126
+
127
+ pub fn add_pre_handler(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
128
+ self.pre_handler.push(hook);
129
+ }
130
+
131
+ pub fn add_on_response(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
132
+ self.on_response.push(hook);
133
+ }
134
+
135
+ pub fn add_on_error(&mut self, hook: Arc<CoreHook<Req, Resp>>) {
136
+ self.on_error.push(hook);
137
+ }
138
+
139
+ pub async fn execute_on_request(&self, mut req: Req) -> Result<HookResult<Req, Resp>, String> {
140
+ if self.on_request.is_empty() {
141
+ return Ok(HookResult::Continue(req));
142
+ }
143
+
144
+ for hook in &self.on_request {
145
+ match hook.execute_request(req).await? {
146
+ HookResult::Continue(r) => req = r,
147
+ HookResult::ShortCircuit(response) => return Ok(HookResult::ShortCircuit(response)),
148
+ }
149
+ }
150
+
151
+ Ok(HookResult::Continue(req))
152
+ }
153
+
154
+ pub async fn execute_pre_validation(&self, mut req: Req) -> Result<HookResult<Req, Resp>, String> {
155
+ if self.pre_validation.is_empty() {
156
+ return Ok(HookResult::Continue(req));
157
+ }
158
+
159
+ for hook in &self.pre_validation {
160
+ match hook.execute_request(req).await? {
161
+ HookResult::Continue(r) => req = r,
162
+ HookResult::ShortCircuit(response) => return Ok(HookResult::ShortCircuit(response)),
163
+ }
164
+ }
165
+
166
+ Ok(HookResult::Continue(req))
167
+ }
168
+
169
+ pub async fn execute_pre_handler(&self, mut req: Req) -> Result<HookResult<Req, Resp>, String> {
170
+ if self.pre_handler.is_empty() {
171
+ return Ok(HookResult::Continue(req));
172
+ }
173
+
174
+ for hook in &self.pre_handler {
175
+ match hook.execute_request(req).await? {
176
+ HookResult::Continue(r) => req = r,
177
+ HookResult::ShortCircuit(response) => return Ok(HookResult::ShortCircuit(response)),
178
+ }
179
+ }
180
+
181
+ Ok(HookResult::Continue(req))
182
+ }
183
+
184
+ pub async fn execute_on_response(&self, mut resp: Resp) -> Result<Resp, String> {
185
+ if self.on_response.is_empty() {
186
+ return Ok(resp);
187
+ }
188
+
189
+ for hook in &self.on_response {
190
+ match hook.execute_response(resp).await? {
191
+ HookResult::Continue(r) => resp = r,
192
+ HookResult::ShortCircuit(r) => resp = r,
193
+ }
194
+ }
195
+
196
+ Ok(resp)
197
+ }
198
+
199
+ pub async fn execute_on_error(&self, mut resp: Resp) -> Result<Resp, String> {
200
+ if self.on_error.is_empty() {
201
+ return Ok(resp);
202
+ }
203
+
204
+ for hook in &self.on_error {
205
+ match hook.execute_response(resp).await? {
206
+ HookResult::Continue(r) => resp = r,
207
+ HookResult::ShortCircuit(r) => resp = r,
208
+ }
209
+ }
210
+
211
+ Ok(resp)
212
+ }
213
+ }
214
+
215
+ /// Helper struct for implementing request hooks from closures
216
+ struct RequestHookFn<F, Req, Resp> {
217
+ name: String,
218
+ func: F,
219
+ _marker: std::marker::PhantomData<fn(Req, Resp)>,
220
+ }
221
+
222
+ struct ResponseHookFn<F, Req, Resp> {
223
+ name: String,
224
+ func: F,
225
+ _marker: std::marker::PhantomData<fn(Req, Resp)>,
226
+ }
227
+
228
+ #[cfg(not(target_arch = "wasm32"))]
229
+ impl<F, Fut, Req, Resp> NativeLifecycleHook<Req, Resp> for RequestHookFn<F, Req, Resp>
230
+ where
231
+ F: Fn(Req) -> Fut + Send + Sync,
232
+ Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + Send + 'static,
233
+ Req: Send + 'static,
234
+ Resp: Send + 'static,
235
+ {
236
+ fn name(&self) -> &str {
237
+ &self.name
238
+ }
239
+
240
+ fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureSend<'a, Req, Resp> {
241
+ Box::pin((self.func)(req))
242
+ }
243
+
244
+ fn execute_response<'a>(&'a self, _resp: Resp) -> ResponseHookFutureSend<'a, Resp> {
245
+ Box::pin(async move { Err("Request hook called with response - this is a bug".to_string()) })
246
+ }
247
+ }
248
+
249
+ #[cfg(target_arch = "wasm32")]
250
+ impl<F, Fut, Req, Resp> LocalLifecycleHook<Req, Resp> for RequestHookFn<F, Req, Resp>
251
+ where
252
+ F: Fn(Req) -> Fut + Send + Sync,
253
+ Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + 'static,
254
+ Req: 'static,
255
+ Resp: 'static,
256
+ {
257
+ fn name(&self) -> &str {
258
+ &self.name
259
+ }
260
+
261
+ fn execute_request<'a>(&'a self, req: Req) -> RequestHookFutureLocal<'a, Req, Resp> {
262
+ Box::pin((self.func)(req))
263
+ }
264
+
265
+ fn execute_response<'a>(&'a self, _resp: Resp) -> ResponseHookFutureLocal<'a, Resp> {
266
+ Box::pin(async move { Err("Request hook called with response - this is a bug".to_string()) })
267
+ }
268
+ }
269
+
270
+ #[cfg(not(target_arch = "wasm32"))]
271
+ impl<F, Fut, Req, Resp> NativeLifecycleHook<Req, Resp> for ResponseHookFn<F, Req, Resp>
272
+ where
273
+ F: Fn(Resp) -> Fut + Send + Sync,
274
+ Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + Send + 'static,
275
+ Req: Send + 'static,
276
+ Resp: Send + 'static,
277
+ {
278
+ fn name(&self) -> &str {
279
+ &self.name
280
+ }
281
+
282
+ fn execute_request<'a>(&'a self, _req: Req) -> RequestHookFutureSend<'a, Req, Resp> {
283
+ Box::pin(async move { Err("Response hook called with request - this is a bug".to_string()) })
284
+ }
285
+
286
+ fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureSend<'a, Resp> {
287
+ Box::pin((self.func)(resp))
288
+ }
289
+ }
290
+
291
+ #[cfg(target_arch = "wasm32")]
292
+ impl<F, Fut, Req, Resp> LocalLifecycleHook<Req, Resp> for ResponseHookFn<F, Req, Resp>
293
+ where
294
+ F: Fn(Resp) -> Fut + Send + Sync,
295
+ Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + 'static,
296
+ Req: 'static,
297
+ Resp: 'static,
298
+ {
299
+ fn name(&self) -> &str {
300
+ &self.name
301
+ }
302
+
303
+ fn execute_request<'a>(&'a self, _req: Req) -> RequestHookFutureLocal<'a, Req, Resp> {
304
+ Box::pin(async move { Err("Response hook called with request - this is a bug".to_string()) })
305
+ }
306
+
307
+ fn execute_response<'a>(&'a self, resp: Resp) -> ResponseHookFutureLocal<'a, Resp> {
308
+ Box::pin((self.func)(resp))
309
+ }
310
+ }
311
+
312
+ /// Builder Pattern for LifecycleHooks
313
+ pub struct LifecycleHooksBuilder<Req, Resp> {
314
+ hooks: LifecycleHooks<Req, Resp>,
315
+ }
316
+
317
+ impl<Req, Resp> LifecycleHooksBuilder<Req, Resp> {
318
+ pub fn new() -> Self {
319
+ Self {
320
+ hooks: LifecycleHooks::default(),
321
+ }
322
+ }
323
+
324
+ pub fn on_request(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
325
+ self.hooks.add_on_request(hook);
326
+ self
327
+ }
328
+
329
+ pub fn pre_validation(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
330
+ self.hooks.add_pre_validation(hook);
331
+ self
332
+ }
333
+
334
+ pub fn pre_handler(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
335
+ self.hooks.add_pre_handler(hook);
336
+ self
337
+ }
338
+
339
+ pub fn on_response(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
340
+ self.hooks.add_on_response(hook);
341
+ self
342
+ }
343
+
344
+ pub fn on_error(mut self, hook: Arc<CoreHook<Req, Resp>>) -> Self {
345
+ self.hooks.add_on_error(hook);
346
+ self
347
+ }
348
+
349
+ pub fn build(self) -> LifecycleHooks<Req, Resp> {
350
+ self.hooks
351
+ }
352
+ }
353
+
354
+ impl<Req, Resp> Default for LifecycleHooksBuilder<Req, Resp> {
355
+ fn default() -> Self {
356
+ Self::new()
357
+ }
358
+ }
359
+
360
+ /// Create a request hook from an async function or closure (native targets).
361
+ #[cfg(not(target_arch = "wasm32"))]
362
+ pub fn request_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
363
+ where
364
+ F: Fn(Req) -> Fut + Send + Sync + 'static,
365
+ Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + Send + 'static,
366
+ Req: Send + 'static,
367
+ Resp: Send + 'static,
368
+ {
369
+ Arc::new(RequestHookFn {
370
+ name: name.into(),
371
+ func,
372
+ _marker: std::marker::PhantomData,
373
+ })
374
+ }
375
+
376
+ /// Create a request hook from an async function or closure (wasm targets).
377
+ #[cfg(target_arch = "wasm32")]
378
+ pub fn request_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
379
+ where
380
+ F: Fn(Req) -> Fut + Send + Sync + 'static,
381
+ Fut: Future<Output = Result<HookResult<Req, Resp>, String>> + 'static,
382
+ Req: 'static,
383
+ Resp: 'static,
384
+ {
385
+ Arc::new(RequestHookFn {
386
+ name: name.into(),
387
+ func,
388
+ _marker: std::marker::PhantomData,
389
+ })
390
+ }
391
+
392
+ /// Create a response hook from an async function or closure (native targets).
393
+ #[cfg(not(target_arch = "wasm32"))]
394
+ pub fn response_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
395
+ where
396
+ F: Fn(Resp) -> Fut + Send + Sync + 'static,
397
+ Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + Send + 'static,
398
+ Req: Send + 'static,
399
+ Resp: Send + 'static,
400
+ {
401
+ Arc::new(ResponseHookFn {
402
+ name: name.into(),
403
+ func,
404
+ _marker: std::marker::PhantomData,
405
+ })
406
+ }
407
+
408
+ /// Create a response hook from an async function or closure (wasm targets).
409
+ #[cfg(target_arch = "wasm32")]
410
+ pub fn response_hook<Req, Resp, F, Fut>(name: impl Into<String>, func: F) -> Arc<dyn LifecycleHook<Req, Resp>>
411
+ where
412
+ F: Fn(Resp) -> Fut + Send + Sync + 'static,
413
+ Fut: Future<Output = Result<HookResult<Resp, Resp>, String>> + 'static,
414
+ Req: 'static,
415
+ Resp: 'static,
416
+ {
417
+ Arc::new(ResponseHookFn {
418
+ name: name.into(),
419
+ func,
420
+ _marker: std::marker::PhantomData,
421
+ })
422
+ }