refactor all to async/await (#617)
Co-authored-by: Danny Browning <danny.browning@protectwise.com> Co-authored-by: Daniel Eades <danieleades@hotmail.com>
This commit is contained in:
		
							
								
								
									
										61
									
								
								src/error.rs
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								src/error.rs
									
									
									
									
									
								
							| @@ -2,8 +2,6 @@ use std::error::Error as StdError; | ||||
| use std::fmt; | ||||
| use std::io; | ||||
|  | ||||
| use tokio_executor::EnterError; | ||||
|  | ||||
| use crate::{StatusCode, Url}; | ||||
|  | ||||
| /// The Errors that may occur when processing a `Request`. | ||||
| @@ -95,7 +93,6 @@ impl Error { | ||||
|     } | ||||
|  | ||||
|     pub(crate) fn with_url(mut self, url: Url) -> Error { | ||||
|         debug_assert_eq!(self.inner.url, None, "with_url overriding existing url"); | ||||
|         self.inner.url = Some(url); | ||||
|         self | ||||
|     } | ||||
| @@ -221,6 +218,13 @@ impl Error { | ||||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub(crate) fn into_io(self) -> io::Error { | ||||
|         match self.inner.kind { | ||||
|             Kind::Io(io) => io, | ||||
|             _ => io::Error::new(io::ErrorKind::Other, self), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Debug for Error { | ||||
| @@ -475,8 +479,8 @@ where | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<EnterError> for Kind { | ||||
|     fn from(_err: EnterError) -> Kind { | ||||
| impl From<tokio_executor::EnterError> for Kind { | ||||
|     fn from(_err: tokio_executor::EnterError) -> Kind { | ||||
|         Kind::BlockingClientInFutureContext | ||||
|     } | ||||
| } | ||||
| @@ -521,10 +525,7 @@ where | ||||
| } | ||||
|  | ||||
| pub(crate) fn into_io(e: Error) -> io::Error { | ||||
|     match e.inner.kind { | ||||
|         Kind::Io(io) => io, | ||||
|         _ => io::Error::new(io::ErrorKind::Other, e), | ||||
|     } | ||||
|     e.into_io() | ||||
| } | ||||
|  | ||||
| pub(crate) fn from_io(e: io::Error) -> Error { | ||||
| @@ -538,39 +539,12 @@ pub(crate) fn from_io(e: io::Error) -> Error { | ||||
|     } | ||||
| } | ||||
|  | ||||
| macro_rules! try_ { | ||||
|     ($e:expr) => { | ||||
|         match $e { | ||||
|             Ok(v) => v, | ||||
|             Err(err) => { | ||||
|                 return Err(crate::error::from(err)); | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| macro_rules! url_error { | ||||
|     ($e:expr, $url:expr) => { | ||||
|         match $e { | ||||
|             Ok(v) => v, | ||||
|             Err(err) => { | ||||
|                 return Err(crate::Error::from(crate::error::InternalFrom( | ||||
|                     err, | ||||
|                     Some($url.clone()), | ||||
|                 ))); | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| } | ||||
|  | ||||
| macro_rules! try_io { | ||||
|     ($e:expr) => { | ||||
|         match $e { | ||||
|             Ok(v) => v, | ||||
|             Err(ref err) if err.kind() == std::io::ErrorKind::WouldBlock => { | ||||
|                 return Ok(futures::Async::NotReady); | ||||
|             } | ||||
|             Err(err) => { | ||||
|                 return Err(crate::error::from_io(err)); | ||||
|             } | ||||
|         } | ||||
|         Err(crate::Error::from(crate::error::InternalFrom( | ||||
|             $e, | ||||
|             Some($url.clone()), | ||||
|         ))) | ||||
|     }; | ||||
| } | ||||
|  | ||||
| @@ -607,6 +581,9 @@ pub(crate) fn unknown_proxy_scheme() -> Error { | ||||
| mod tests { | ||||
|     use super::*; | ||||
|  | ||||
|     fn assert_send<T: Send>() {} | ||||
|     fn assert_sync<T: Sync>() {} | ||||
|  | ||||
|     #[allow(deprecated)] | ||||
|     #[test] | ||||
|     fn test_cause_chain() { | ||||
| @@ -652,6 +629,8 @@ mod tests { | ||||
|         let err = Error::new(Kind::Io(io), None); | ||||
|         assert!(err.cause().is_some()); | ||||
|         assert_eq!(err.to_string(), "chain: root"); | ||||
|         assert_send::<Error>(); | ||||
|         assert_sync::<Error>(); | ||||
|     } | ||||
|  | ||||
|     #[test] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user