52
52
//! io.ns("/", handler);
53
53
//! io.ns("/admin", handler);
54
54
//! ```
55
+
55
56
use std:: pin:: Pin ;
56
57
use std:: sync:: Arc ;
57
58
@@ -66,6 +67,7 @@ pub(crate) type BoxedConnectHandler<A> = Box<dyn ErasedConnectHandler<A>>;
66
67
67
68
type MiddlewareRes = Result < ( ) , Box < dyn std:: fmt:: Display + Send > > ;
68
69
type MiddlewareResFut < ' a > = Pin < Box < dyn Future < Output = MiddlewareRes > + Send + ' a > > ;
70
+
69
71
pub ( crate ) trait ErasedConnectHandler < A : Adapter > : Send + Sync + ' static {
70
72
fn call ( & self , s : Arc < Socket < A > > , auth : Option < String > ) ;
71
73
fn call_middleware < ' a > (
@@ -100,7 +102,7 @@ pub trait ConnectMiddleware<A: Adapter, T>: Send + Sync + 'static {
100
102
) -> impl Future < Output = MiddlewareRes > + Send ;
101
103
102
104
#[ doc( hidden) ]
103
- fn phantom ( & self ) -> std:: marker:: PhantomData < T > {
105
+ fn phantom ( & self ) -> std:: marker:: PhantomData < ( A , T ) > {
104
106
std:: marker:: PhantomData
105
107
}
106
108
}
@@ -144,6 +146,19 @@ pub trait ConnectHandler<A: Adapter, T>: Send + Sync + 'static {
144
146
}
145
147
}
146
148
149
+ /// A layered handler, used to compose a [`ConnectHandler`] with a [`ConnectMiddleware`]
150
+ pub struct LayeredConnectHandler < A , H , M , T , T1 > {
151
+ handler : H ,
152
+ middleware : M ,
153
+ phantom : std:: marker:: PhantomData < ( A , T , T1 ) > ,
154
+ }
155
+
156
+ struct ConnectMiddlewareLayer < M , N , T , T1 > {
157
+ middleware : M ,
158
+ next : N ,
159
+ phantom : std:: marker:: PhantomData < ( T , T1 ) > ,
160
+ }
161
+
147
162
impl < A : Adapter , T , H > MakeErasedHandler < H , A , T >
148
163
where
149
164
H : ConnectHandler < A , T > + Send + Sync + ' static ,
@@ -174,12 +189,6 @@ where
174
189
}
175
190
}
176
191
177
- pub struct LayeredConnectHandler < A , H , M , T , T1 > {
178
- handler : H ,
179
- middleware : M ,
180
- phantom : std:: marker:: PhantomData < ( A , T , T1 ) > ,
181
- }
182
-
183
192
impl < A , H , M , T , T1 > LayeredConnectHandler < A , H , M , T , T1 >
184
193
where
185
194
A : Adapter ,
@@ -192,7 +201,7 @@ where
192
201
pub fn with < N , T2 > (
193
202
self ,
194
203
next : N ,
195
- ) -> LayeredConnectHandler < A , H , ConnectMiddlewareLayer < A , M , N , T1 , T2 > , T , T2 >
204
+ ) -> LayeredConnectHandler < A , H , impl ConnectMiddleware < A , T1 > , T , T2 >
196
205
where
197
206
N : ConnectMiddleware < A , T2 > + Send + Sync + ' static ,
198
207
T2 : Send + Sync + ' static ,
@@ -208,11 +217,7 @@ where
208
217
}
209
218
}
210
219
}
211
- pub struct ConnectMiddlewareLayer < A , M , N , T , T1 > {
212
- middleware : M ,
213
- next : N ,
214
- phantom : std:: marker:: PhantomData < ( A , T , T1 ) > ,
215
- }
220
+
216
221
impl < A , H , M , T , T1 > ConnectHandler < A , T > for LayeredConnectHandler < A , H , M , T , T1 >
217
222
where
218
223
A : Adapter ,
@@ -246,7 +251,7 @@ where
246
251
}
247
252
}
248
253
249
- impl < A , M , N , T , T1 > ConnectMiddleware < A , T > for ConnectMiddlewareLayer < A , M , N , T , T1 >
254
+ impl < A , M , N , T , T1 > ConnectMiddleware < A , T > for ConnectMiddlewareLayer < M , N , T , T1 >
250
255
where
251
256
A : Adapter ,
252
257
M : ConnectMiddleware < A , T > + Send + Sync + ' static ,
@@ -348,7 +353,6 @@ macro_rules! impl_middleware_async {
348
353
Err ( _e) => {
349
354
#[ cfg( feature = "tracing" ) ]
350
355
tracing:: error!( "Error while extracting data: {}" , _e) ;
351
- //TODO: handle error
352
356
return Ok ( ( ) ) ;
353
357
} ,
354
358
} ;
0 commit comments