@@ -10,6 +10,7 @@ use std::task::{Context, Poll};
1010use std:: time:: Duration ;
1111
1212use crate :: rt:: { Read , Write } ;
13+ use crate :: upgrade:: Upgraded ;
1314use bytes:: Bytes ;
1415
1516use crate :: body:: { Body , Incoming as IncomingBody } ;
@@ -191,11 +192,11 @@ where
191192 /// Enable this connection to support higher-level HTTP upgrades.
192193 ///
193194 /// 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 >
195196 where
196197 I : Send ,
197198 {
198- upgrades :: UpgradeableConnection { inner : Some ( self ) }
199+ UpgradeableConnection { inner : Some ( self ) }
199200 }
200201}
201202
@@ -433,60 +434,52 @@ impl Builder {
433434 }
434435}
435436
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+ }
452446
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 ( )
468461 }
462+ }
469463
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 < ( ) > ;
479473
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 ( ( ) ) )
489481 }
482+ Err ( e) => Poll :: Ready ( Err ( e) ) ,
490483 }
491484 }
492485}
0 commit comments