@@ -10,6 +10,7 @@ use std::task::{Context, Poll};
10
10
use std:: time:: Duration ;
11
11
12
12
use crate :: rt:: { Read , Write } ;
13
+ use crate :: upgrade:: Upgraded ;
13
14
use bytes:: Bytes ;
14
15
15
16
use crate :: body:: { Body , Incoming as IncomingBody } ;
@@ -191,11 +192,11 @@ where
191
192
/// Enable this connection to support higher-level HTTP upgrades.
192
193
///
193
194
/// See [the `upgrade` module](crate::upgrade) for more.
194
- pub fn with_upgrades ( self ) -> upgrades :: UpgradeableConnection < I , S >
195
+ pub fn with_upgrades ( self ) -> UpgradeableConnection < I , S >
195
196
where
196
197
I : Send ,
197
198
{
198
- upgrades :: UpgradeableConnection { inner : Some ( self ) }
199
+ UpgradeableConnection { inner : Some ( self ) }
199
200
}
200
201
}
201
202
@@ -433,60 +434,52 @@ impl Builder {
433
434
}
434
435
}
435
436
436
- mod upgrades {
437
- use crate :: upgrade:: Upgraded ;
438
-
439
- use super :: * ;
440
-
441
- // A future binding a connection with a Service with Upgrade support.
442
- //
443
- // This type is unnameable outside the crate.
444
- #[ must_use = "futures do nothing unless polled" ]
445
- #[ allow( missing_debug_implementations) ]
446
- pub struct UpgradeableConnection < T , S >
447
- where
448
- S : HttpService < IncomingBody > ,
449
- {
450
- pub ( super ) inner : Option < Connection < T , S > > ,
451
- }
437
+ /// A future binding a connection with a Service with Upgrade support.
438
+ #[ must_use = "futures do nothing unless polled" ]
439
+ #[ allow( missing_debug_implementations) ]
440
+ pub struct UpgradeableConnection < T , S >
441
+ where
442
+ S : HttpService < IncomingBody > ,
443
+ {
444
+ pub ( super ) inner : Option < Connection < T , S > > ,
445
+ }
452
446
453
- impl < I , B , S > UpgradeableConnection < I , S >
454
- where
455
- S : HttpService < IncomingBody , ResBody = B > ,
456
- S :: Error : Into < Box < dyn StdError + Send + Sync > > ,
457
- I : Read + Write + Unpin ,
458
- B : Body + ' static ,
459
- B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
460
- {
461
- /// Start a graceful shutdown process for this connection.
462
- ///
463
- /// This `Connection` should continue to be polled until shutdown
464
- /// can finish.
465
- pub fn graceful_shutdown ( mut self : Pin < & mut Self > ) {
466
- Pin :: new ( self . inner . as_mut ( ) . unwrap ( ) ) . graceful_shutdown ( )
467
- }
447
+ impl < I , B , S > UpgradeableConnection < I , S >
448
+ where
449
+ S : HttpService < IncomingBody , ResBody = B > ,
450
+ S :: Error : Into < Box < dyn StdError + Send + Sync > > ,
451
+ I : Read + Write + Unpin ,
452
+ B : Body + ' static ,
453
+ B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
454
+ {
455
+ /// Start a graceful shutdown process for this connection.
456
+ ///
457
+ /// This `Connection` should continue to be polled until shutdown
458
+ /// can finish.
459
+ pub fn graceful_shutdown ( mut self : Pin < & mut Self > ) {
460
+ Pin :: new ( self . inner . as_mut ( ) . unwrap ( ) ) . graceful_shutdown ( )
468
461
}
462
+ }
469
463
470
- impl < I , B , S > Future for UpgradeableConnection < I , S >
471
- where
472
- S : HttpService < IncomingBody , ResBody = B > ,
473
- S :: Error : Into < Box < dyn StdError + Send + Sync > > ,
474
- I : Read + Write + Unpin + Send + ' static ,
475
- B : Body + ' static ,
476
- B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
477
- {
478
- type Output = crate :: Result < ( ) > ;
464
+ impl < I , B , S > Future for UpgradeableConnection < I , S >
465
+ where
466
+ S : HttpService < IncomingBody , ResBody = B > ,
467
+ S :: Error : Into < Box < dyn StdError + Send + Sync > > ,
468
+ I : Read + Write + Unpin + Send + ' static ,
469
+ B : Body + ' static ,
470
+ B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
471
+ {
472
+ type Output = crate :: Result < ( ) > ;
479
473
480
- fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
481
- match ready ! ( Pin :: new( & mut self . inner. as_mut( ) . unwrap( ) . conn) . poll( cx) ) {
482
- Ok ( proto:: Dispatched :: Shutdown ) => Poll :: Ready ( Ok ( ( ) ) ) ,
483
- Ok ( proto:: Dispatched :: Upgrade ( pending) ) => {
484
- let ( io, buf, _) = self . inner . take ( ) . unwrap ( ) . conn . into_inner ( ) ;
485
- pending. fulfill ( Upgraded :: new ( io, buf) ) ;
486
- Poll :: Ready ( Ok ( ( ) ) )
487
- }
488
- Err ( e) => Poll :: Ready ( Err ( e) ) ,
474
+ fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
475
+ match ready ! ( Pin :: new( & mut self . inner. as_mut( ) . unwrap( ) . conn) . poll( cx) ) {
476
+ Ok ( proto:: Dispatched :: Shutdown ) => Poll :: Ready ( Ok ( ( ) ) ) ,
477
+ Ok ( proto:: Dispatched :: Upgrade ( pending) ) => {
478
+ let ( io, buf, _) = self . inner . take ( ) . unwrap ( ) . conn . into_inner ( ) ;
479
+ pending. fulfill ( Upgraded :: new ( io, buf) ) ;
480
+ Poll :: Ready ( Ok ( ( ) ) )
489
481
}
482
+ Err ( e) => Poll :: Ready ( Err ( e) ) ,
490
483
}
491
484
}
492
485
}
0 commit comments