@@ -30,12 +30,6 @@ pub struct IntoMakeServiceWithConnectInfo<S, C> {
30
30
_connect_info : PhantomData < fn ( ) -> C > ,
31
31
}
32
32
33
- #[ test]
34
- fn traits ( ) {
35
- use crate :: test_helpers:: * ;
36
- assert_send :: < IntoMakeServiceWithConnectInfo < ( ) , NotSendSync > > ( ) ;
37
- }
38
-
39
33
impl < S , C > IntoMakeServiceWithConnectInfo < S , C > {
40
34
pub ( crate ) fn new ( svc : S ) -> Self {
41
35
Self {
@@ -85,22 +79,13 @@ pub trait Connected<T>: Clone + Send + Sync + 'static {
85
79
#[ cfg( all( feature = "tokio" , any( feature = "http1" , feature = "http2" ) ) ) ]
86
80
const _: ( ) = {
87
81
use crate :: serve;
88
- use tokio:: net:: TcpListener ;
89
82
90
- impl Connected < serve:: IncomingStream < ' _ , TcpListener > > for SocketAddr {
91
- fn connect_info ( stream : serve:: IncomingStream < ' _ , TcpListener > ) -> Self {
92
- * stream. remote_addr ( )
93
- }
94
- }
95
-
96
- impl < ' a , L , F > Connected < serve:: IncomingStream < ' a , serve:: TapIo < L , F > > > for L :: Addr
83
+ impl < L > Connected < serve:: IncomingStream < ' _ , L > > for SocketAddr
97
84
where
98
- L : serve:: Listener ,
99
- L :: Addr : Clone + Sync + ' static ,
100
- F : FnMut ( & mut L :: Io ) + Send + ' static ,
85
+ L : serve:: Listener < Addr = Self > ,
101
86
{
102
- fn connect_info ( stream : serve:: IncomingStream < ' a , serve :: TapIo < L , F > > ) -> Self {
103
- stream. remote_addr ( ) . clone ( )
87
+ fn connect_info ( stream : serve:: IncomingStream < ' _ , L > ) -> Self {
88
+ * stream. remote_addr ( )
104
89
}
105
90
}
106
91
} ;
@@ -234,8 +219,90 @@ where
234
219
#[ cfg( test) ]
235
220
mod tests {
236
221
use super :: * ;
237
- use crate :: { routing:: get, serve:: IncomingStream , test_helpers:: TestClient , Router } ;
238
- use tokio:: net:: TcpListener ;
222
+ use crate :: {
223
+ extract:: connect_info:: Connected , routing:: get, serve:: IncomingStream , serve:: Listener ,
224
+ test_helpers:: TestClient , Router ,
225
+ } ;
226
+ use tokio:: net:: { TcpListener , TcpStream } ;
227
+
228
+ #[ test]
229
+ fn into_make_service_traits ( ) {
230
+ use crate :: test_helpers:: * ;
231
+ assert_send :: < IntoMakeServiceWithConnectInfo < ( ) , NotSendSync > > ( ) ;
232
+ }
233
+
234
+ #[ allow( dead_code) ]
235
+ #[ allow( clippy:: todo) ]
236
+ fn connected_traits ( ) {
237
+ // Test that the `Connected` trait can be used with custom address and listener types.
238
+
239
+ fn create_router ( ) -> Router {
240
+ todo ! ( )
241
+ }
242
+
243
+ fn tcp_listener ( ) -> TcpListener {
244
+ todo ! ( )
245
+ }
246
+
247
+ #[ derive( Clone ) ]
248
+ struct CustomAddr ( SocketAddr ) ;
249
+
250
+ impl Connected < IncomingStream < ' _ , TcpListener > > for CustomAddr {
251
+ fn connect_info ( _stream : IncomingStream < ' _ , TcpListener > ) -> Self {
252
+ todo ! ( )
253
+ }
254
+ }
255
+
256
+ impl Connected < IncomingStream < ' _ , CustomListener > > for CustomAddr {
257
+ fn connect_info ( _stream : IncomingStream < ' _ , CustomListener > ) -> Self {
258
+ todo ! ( )
259
+ }
260
+ }
261
+
262
+ struct CustomListener { }
263
+
264
+ impl Listener for CustomListener {
265
+ type Io = TcpStream ;
266
+ type Addr = SocketAddr ;
267
+
268
+ async fn accept ( & mut self ) -> ( Self :: Io , Self :: Addr ) {
269
+ todo ! ( )
270
+ }
271
+
272
+ fn local_addr ( & self ) -> tokio:: io:: Result < Self :: Addr > {
273
+ todo ! ( )
274
+ }
275
+ }
276
+
277
+ fn custom_connected ( ) {
278
+ let router = create_router ( ) ;
279
+ let _ = crate :: serve (
280
+ tcp_listener ( ) ,
281
+ router. into_make_service_with_connect_info :: < CustomAddr > ( ) ,
282
+ ) ;
283
+ }
284
+
285
+ fn custom_listener ( ) {
286
+ let router = create_router ( ) ;
287
+ let _ = crate :: serve ( CustomListener { } , router. into_make_service ( ) ) ;
288
+ }
289
+
290
+ fn custom_listener_with_connect ( ) {
291
+ let router = create_router ( ) ;
292
+ let _ = crate :: serve (
293
+ CustomListener { } ,
294
+ router. into_make_service_with_connect_info :: < SocketAddr > ( ) ,
295
+ ) ;
296
+ }
297
+
298
+ fn custom_listener_with_custom_connect ( ) {
299
+ let router = create_router ( ) ;
300
+ let _ = crate :: serve (
301
+ CustomListener { } ,
302
+ router. into_make_service_with_connect_info :: < CustomAddr > ( ) ,
303
+ ) ;
304
+ }
305
+ }
239
306
240
307
#[ crate :: test]
241
308
async fn socket_addr ( ) {
0 commit comments