@@ -17,6 +17,7 @@ use self::Error::{
1717 Status ,
1818 Timeout ,
1919 Upgrade ,
20+ Cancel ,
2021 Io ,
2122 TooLarge ,
2223 Incomplete ,
@@ -47,6 +48,8 @@ pub enum Error {
4748 Timeout ,
4849 /// A protocol upgrade was encountered, but not yet supported in hyper.
4950 Upgrade ,
51+ /// A pending item was dropped before ever being processed.
52+ Cancel ( Canceled ) ,
5053 /// An `io::Error` that occurred while trying to read or write to a network stream.
5154 Io ( IoError ) ,
5255 /// Parsing a field as string failed
@@ -56,6 +59,45 @@ pub enum Error {
5659 __Nonexhaustive( Void )
5760}
5861
62+ impl Error {
63+ pub ( crate ) fn new_canceled ( ) -> Error {
64+ Error :: Cancel ( Canceled {
65+ _inner : ( ) ,
66+ } )
67+ }
68+ }
69+
70+ /// A pending item was dropped before ever being processed.
71+ ///
72+ /// For example, a `Request` could be queued in the `Client`, *just*
73+ /// as the related connection gets closed by the remote. In that case,
74+ /// when the connection drops, the pending response future will be
75+ /// fulfilled with this error, signaling the `Request` was never started.
76+ pub struct Canceled {
77+ // maybe in the future this contains an optional value of
78+ // what was canceled?
79+ _inner : ( ) ,
80+ }
81+
82+ impl Canceled {
83+ fn description ( & self ) -> & str {
84+ "an operation was canceled internally before starting"
85+ }
86+ }
87+
88+ impl fmt:: Debug for Canceled {
89+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
90+ f. debug_struct ( "Canceled" )
91+ . finish ( )
92+ }
93+ }
94+
95+ impl fmt:: Display for Canceled {
96+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
97+ f. pad ( self . description ( ) )
98+ }
99+ }
100+
59101#[ doc( hidden) ]
60102pub struct Void ( ( ) ) ;
61103
@@ -87,6 +129,7 @@ impl StdError for Error {
87129 Incomplete => "message is incomplete" ,
88130 Timeout => "timeout" ,
89131 Upgrade => "unsupported protocol upgrade" ,
132+ Cancel ( ref e) => e. description ( ) ,
90133 Uri ( ref e) => e. description ( ) ,
91134 Io ( ref e) => e. description ( ) ,
92135 Utf8 ( ref e) => e. description ( ) ,
@@ -143,6 +186,11 @@ impl From<httparse::Error> for Error {
143186 }
144187}
145188
189+ #[ doc( hidden) ]
190+ trait AssertSendSync : Send + Sync + ' static { }
191+ #[ doc( hidden) ]
192+ impl AssertSendSync for Error { }
193+
146194#[ cfg( test) ]
147195mod tests {
148196 use std:: error:: Error as StdError ;
0 commit comments