From 56e2edd4fdaa5cc9118db243a28ba2df8b8f5cf0 Mon Sep 17 00:00:00 2001 From: Lewin Bormann Date: Tue, 11 Jun 2019 23:49:41 +0200 Subject: [PATCH] chore(syntax): Use `dyn` everywhere to prepare for deprecation. --- src/authenticator.rs | 14 +++++++------- src/authenticator_delegate.rs | 2 +- src/installed.rs | 15 ++++++++------- src/service_account.rs | 11 +++++++---- src/types.rs | 4 ++-- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/authenticator.rs b/src/authenticator.rs index 5863d0c..3667961 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -44,7 +44,7 @@ pub struct Authenticator { /// The `api_key()` method is an alternative in case there are no scopes or /// if no user is involved. pub trait GetToken { - fn token<'b, I, T>(&mut self, scopes: I) -> Result> + fn token<'b, I, T>(&mut self, scopes: I) -> Result> where T: AsRef + Ord + 'b, I: IntoIterator; @@ -87,7 +87,7 @@ where } } - fn do_installed_flow(&mut self, scopes: &Vec<&str>) -> Result> { + fn do_installed_flow(&mut self, scopes: &Vec<&str>) -> Result> { let installed_type; match self.flow_type { @@ -108,7 +108,7 @@ where &mut self, scopes: &Vec<&str>, code_url: String, - ) -> Result> { + ) -> Result> { let mut flow = DeviceFlow::new(self.client.clone(), &self.secret, &code_url); // PHASE 1: REQUEST CODE @@ -121,14 +121,14 @@ where match res_err { RequestError::ClientError(err) => match self.delegate.client_error(&err) { Retry::Abort | Retry::Skip => { - return Err(Box::new(StringError::from(&err as &Error))); + return Err(Box::new(StringError::from(&err as &dyn Error))); } Retry::After(d) => sleep(d), }, RequestError::HttpError(err) => { match self.delegate.connection_error(&err) { Retry::Abort | Retry::Skip => { - return Err(Box::new(StringError::from(&err as &Error))); + return Err(Box::new(StringError::from(&err as &dyn Error))); } Retry::After(d) => sleep(d), } @@ -159,7 +159,7 @@ where match poll_err { &&PollError::HttpError(ref err) => match self.delegate.client_error(err) { Retry::Abort | Retry::Skip => { - return Err(Box::new(StringError::from(err as &Error))); + return Err(Box::new(StringError::from(err as &dyn Error))); } Retry::After(d) => sleep(d), }, @@ -199,7 +199,7 @@ where /// In any failure case, the delegate will be provided with additional information, and /// the caller will be informed about storage related errors. /// Otherwise it is guaranteed to be valid for the given scopes. - fn token<'b, I, T>(&mut self, scopes: I) -> Result> + fn token<'b, I, T>(&mut self, scopes: I) -> Result> where T: AsRef + Ord + 'b, I: IntoIterator, diff --git a/src/authenticator_delegate.rs b/src/authenticator_delegate.rs index 0d70d5b..b1c793b 100644 --- a/src/authenticator_delegate.rs +++ b/src/authenticator_delegate.rs @@ -77,7 +77,7 @@ pub trait AuthenticatorDelegate { /// This can be useful if the underlying `TokenStorage` may fail occasionally. /// if `is_set` is true, the failure resulted from `TokenStorage.set(...)`. Otherwise, /// it was `TokenStorage.get(...)` - fn token_storage_failure(&mut self, is_set: bool, _: &Error) -> Retry { + fn token_storage_failure(&mut self, is_set: bool, _: &dyn Error) -> Retry { let _ = is_set; Retry::Abort } diff --git a/src/installed.rs b/src/installed.rs index bb9bd91..bc98b8d 100644 --- a/src/installed.rs +++ b/src/installed.rs @@ -119,7 +119,7 @@ where auth_delegate: &mut AD, appsecret: &ApplicationSecret, scopes: S, - ) -> Result> + ) -> Result> where T: AsRef + 'a, S: Iterator, @@ -160,13 +160,13 @@ where auth_delegate: &mut AD, appsecret: &ApplicationSecret, scopes: S, - ) -> Result> + ) -> Result> where T: AsRef + 'a, S: Iterator, { let server = self.server.take(); // Will shutdown the server if present when goes out of scope - let result: Result> = match server { + let result: Result> = match server { None => { let url = build_authentication_request_url( &appsecret.auth_uri, @@ -220,7 +220,7 @@ where appsecret: &ApplicationSecret, authcode: &str, custom_redirect_uri: Option, - ) -> Result> { + ) -> Result> { let redirect_uri = custom_redirect_uri.unwrap_or_else(|| match &self.server { None => OOB_REDIRECT_URI.to_string(), Some(server) => format!("http://localhost:{}", server.port), @@ -263,7 +263,7 @@ where match token_resp { Result::Err(e) => return Result::Err(Box::new(e)), - Result::Ok(tok) => Result::Ok(tok) as Result>, + Result::Ok(tok) => Result::Ok(tok) as Result>, } } } @@ -338,14 +338,15 @@ impl std::ops::Drop for InstalledFlowServer { pub struct InstalledFlowHandlerResponseFuture { inner: Box< - futures::Future, Error = hyper::http::Error> + Send, + dyn futures::Future, Error = hyper::http::Error> + Send, >, } impl InstalledFlowHandlerResponseFuture { fn new( fut: Box< - futures::Future, Error = hyper::http::Error> + Send, + dyn futures::Future, Error = hyper::http::Error> + + Send, >, ) -> Self { Self { inner: fut } diff --git a/src/service_account.rs b/src/service_account.rs index dea4bbb..622e949 100644 --- a/src/service_account.rs +++ b/src/service_account.rs @@ -47,7 +47,7 @@ fn encode_base64>(s: T) -> String { base64::encode_config(s.as_ref(), base64::URL_SAFE) } -fn decode_rsa_key(pem_pkcs8: &str) -> Result> { +fn decode_rsa_key(pem_pkcs8: &str) -> Result> { let private = pem_pkcs8.to_string().replace("\\n", "\n").into_bytes(); let mut private_reader: &[u8] = private.as_ref(); let private_keys = pemfile::pkcs8_private_keys(&mut private_reader); @@ -122,7 +122,7 @@ impl JWT { head } - fn sign(&self, private_key: &str) -> Result> { + fn sign(&self, private_key: &str) -> Result> { let mut jwt_head = self.encode_claims(); let key = decode_rsa_key(private_key)?; let signing_key = sign::RSASigningKey::new(&key) @@ -237,7 +237,10 @@ where } } - fn request_token(&mut self, scopes: &Vec<&str>) -> result::Result> { + fn request_token( + &mut self, + scopes: &Vec<&str>, + ) -> result::Result> { let mut claims = init_claims_from_key(&self.key, scopes); claims.sub = self.sub.clone(); let signed = JWT::new(claims).sign(self.key.private_key.as_ref().unwrap())?; @@ -311,7 +314,7 @@ impl GetToken for ServiceAccountAccess where C: hyper::client::connect::Connect, { - fn token<'b, I, T>(&mut self, scopes: I) -> result::Result> + fn token<'b, I, T>(&mut self, scopes: I) -> result::Result> where T: AsRef + Ord + 'b, I: IntoIterator, diff --git a/src/types.rs b/src/types.rs index 42746c1..dd80bba 100644 --- a/src/types.rs +++ b/src/types.rs @@ -99,8 +99,8 @@ impl StringError { } } -impl<'a> From<&'a Error> for StringError { - fn from(err: &'a Error) -> StringError { +impl<'a> From<&'a dyn Error> for StringError { + fn from(err: &'a dyn Error) -> StringError { StringError::new(err.description().to_string(), None) } }