feat(error): revamp hyper::Error type
				
					
				
			**The `Error` is now an opaque struct**, which allows for more variants to be added freely, and the internal representation to change without being breaking changes. For inspecting an `Error`, there are several `is_*` methods to check for certain classes of errors, such as `Error::is_parse()`. The `cause` can also be inspected, like before. This likely seems like a downgrade, but more inspection can be added as needed! The `Error` now knows about more states, which gives much more context around when a certain error occurs. This is also expressed in the description and `fmt` messages. **Most places where a user would provide an error to hyper can now pass any error type** (`E: Into<Box<std::error::Error>>`). This error is passed back in relevant places, and can be useful for logging. This should make it much clearer about what error a user should provide to hyper: any it feels is relevant! Closes #1128 Closes #1130 Closes #1431 Closes #1338 BREAKING CHANGE: `Error` is no longer an enum to pattern match over, or to construct. Code will need to be updated accordingly. For body streams or `Service`s, inference might be unable to determine what error type you mean to return. Starting in Rust 1.26, you could just label that as `!` if you never return an error.
This commit is contained in:
		| @@ -25,7 +25,7 @@ use super::{HyperService, Request, Response, Service}; | ||||
| pub struct Connection<I, S> | ||||
| where | ||||
|     S: HyperService, | ||||
|     S::ResponseBody: Entity<Error=::Error>, | ||||
|     S::ResponseBody: Entity, | ||||
| { | ||||
|     pub(super) conn: proto::dispatch::Dispatcher< | ||||
|         proto::dispatch::Server<S>, | ||||
| @@ -59,9 +59,11 @@ pub struct Parts<T> { | ||||
| // ===== impl Connection ===== | ||||
|  | ||||
| impl<I, B, S> Connection<I, S> | ||||
| where S: Service<Request = Request<Body>, Response = Response<B>, Error = ::Error> + 'static, | ||||
|       I: AsyncRead + AsyncWrite + 'static, | ||||
|       B: Entity<Error=::Error> + 'static, | ||||
| where | ||||
|     S: Service<Request=Request<Body>, Response=Response<B>> + 'static, | ||||
|     S::Error: Into<Box<::std::error::Error + Send + Sync>>, | ||||
|     I: AsyncRead + AsyncWrite + 'static, | ||||
|     B: Entity + 'static, | ||||
| { | ||||
|     /// Disables keep-alive for this connection. | ||||
|     pub fn disable_keep_alive(&mut self) { | ||||
| @@ -96,9 +98,11 @@ where S: Service<Request = Request<Body>, Response = Response<B>, Error = ::Erro | ||||
| } | ||||
|  | ||||
| impl<I, B, S> Future for Connection<I, S> | ||||
| where S: Service<Request = Request<Body>, Response = Response<B>, Error = ::Error> + 'static, | ||||
|       I: AsyncRead + AsyncWrite + 'static, | ||||
|       B: Entity<Error=::Error> + 'static, | ||||
| where | ||||
|     S: Service<Request=Request<Body>, Response=Response<B>> + 'static, | ||||
|     S::Error: Into<Box<::std::error::Error + Send + Sync>>, | ||||
|     I: AsyncRead + AsyncWrite + 'static, | ||||
|     B: Entity + 'static, | ||||
| { | ||||
|     type Item = (); | ||||
|     type Error = ::Error; | ||||
| @@ -111,7 +115,7 @@ where S: Service<Request = Request<Body>, Response = Response<B>, Error = ::Erro | ||||
| impl<I, S> fmt::Debug for Connection<I, S> | ||||
| where | ||||
|     S: HyperService, | ||||
|     S::ResponseBody: Entity<Error=::Error>, | ||||
|     S::ResponseBody: Entity, | ||||
| { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         f.debug_struct("Connection") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user