diff --git a/examples/drive_example/src/main.rs b/examples/drive_example/src/main.rs index 1cb8180..5984ce9 100644 --- a/examples/drive_example/src/main.rs +++ b/examples/drive_example/src/main.rs @@ -34,7 +34,7 @@ fn main() { let authenticator = Authenticator::new(&secret, DefaultAuthenticatorDelegate, client, - DiskTokenStorage::new(&"token_store.json".to_string()) + DiskTokenStorage::new("token_store.json") .unwrap(), Some(FlowType::InstalledInteractive)); let client = hyper::Client::with_connector( diff --git a/examples/service_account/src/main.rs b/examples/service_account/src/main.rs index 99afa4a..e849477 100644 --- a/examples/service_account/src/main.rs +++ b/examples/service_account/src/main.rs @@ -165,7 +165,7 @@ fn publish_stuff(methods: &PubsubMethods, message: &str) { // If called as '.../service_account pub', act as publisher; if called as '.../service_account // sub', act as subscriber. fn main() { - let client_secret = oauth::service_account_key_from_file(&"pubsub-auth.json".to_string()) + let client_secret = oauth::service_account_key_from_file("pubsub-auth.json") .unwrap(); let client = hyper::Client::with_connector(HttpsConnector::new(NativeTlsClient::new().unwrap())); let mut access = oauth::ServiceAccountAccess::new(client_secret, client); diff --git a/src/authenticator.rs b/src/authenticator.rs index 2791080..94cf514 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -238,8 +238,7 @@ where } } RefreshResult::RefreshError(ref err_str, ref err_description) => { - self.delegate - .token_refresh_failed(&err_str, &err_description); + self.delegate.token_refresh_failed(err_str, err_description); let storage_err = match self.storage.set(scope_key, &scopes, None) { Ok(_) => String::new(), diff --git a/src/authenticator_delegate.rs b/src/authenticator_delegate.rs index affb1ca..e7dd846 100644 --- a/src/authenticator_delegate.rs +++ b/src/authenticator_delegate.rs @@ -90,7 +90,11 @@ pub trait AuthenticatorDelegate { /// Called if we could not acquire a refresh token for a reason possibly specified /// by the server. /// This call is made for the delegate's information only. - fn token_refresh_failed(&mut self, error: &String, error_description: &Option) { + fn token_refresh_failed>( + &mut self, + error: S, + error_description: &Option, + ) { { let _ = error; } @@ -136,7 +140,11 @@ pub trait AuthenticatorDelegate { /// We need the user to navigate to a URL using their browser and potentially paste back a code /// (or maybe not). Whether they have to enter a code depends on the InstalledFlowReturnMethod /// used. - fn present_user_url(&mut self, url: &String, need_code: bool) -> Option { + fn present_user_url + fmt::Display>( + &mut self, + url: S, + need_code: bool, + ) -> Option { if need_code { println!( "Please direct your browser to {}, follow the instructions and enter the \ diff --git a/src/device.rs b/src/device.rs index ee6ddb1..db3bafa 100644 --- a/src/device.rs +++ b/src/device.rs @@ -314,7 +314,7 @@ pub mod tests { fn working_flow() { use crate::helper::parse_application_secret; - let appsecret = parse_application_secret(&TEST_APP_SECRET.to_string()).unwrap(); + let appsecret = parse_application_secret(TEST_APP_SECRET).unwrap(); let mut flow = DeviceFlow::new( hyper::Client::with_connector(::default()), &appsecret, diff --git a/src/helper.rs b/src/helper.rs index 15675ea..f17b489 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -28,8 +28,9 @@ pub fn read_application_secret(path: &Path) -> io::Result { } /// Read an application secret from a JSON string. -pub fn parse_application_secret(secret: &String) -> io::Result { - let result: serde_json::Result = serde_json::from_str(secret); +pub fn parse_application_secret>(secret: S) -> io::Result { + let result: serde_json::Result = + serde_json::from_str(secret.as_ref()); match result { Err(e) => Err(io::Error::new( io::ErrorKind::InvalidData, @@ -52,7 +53,7 @@ pub fn parse_application_secret(secret: &String) -> io::Result io::Result { +pub fn service_account_key_from_file>(path: S) -> io::Result { let mut key = String::new(); let mut file = fs::OpenOptions::new().read(true).open(path)?; file.read_to_string(&mut key)?; diff --git a/src/refresh.rs b/src/refresh.rs index 2bd20bf..06e585d 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -166,7 +166,7 @@ mod tests { #[test] fn refresh_flow() { - let appsecret = parse_application_secret(&TEST_APP_SECRET.to_string()).unwrap(); + let appsecret = parse_application_secret(TEST_APP_SECRET).unwrap(); let mut c = hyper::Client::with_connector(::default()); let mut flow = RefreshFlow::new(&mut c); diff --git a/src/service_account.rs b/src/service_account.rs index 104d7f9..60ebc27 100644 --- a/src/service_account.rs +++ b/src/service_account.rs @@ -351,7 +351,7 @@ mod tests { //#[test] #[allow(dead_code)] fn test_service_account_e2e() { - let key = service_account_key_from_file(&TEST_PRIVATE_KEY_PATH.to_string()).unwrap(); + let key = service_account_key_from_file(TEST_PRIVATE_KEY_PATH).unwrap(); let client = hyper::Client::with_connector(HttpsConnector::new(NativeTlsClient::new().unwrap())); let mut acc = ServiceAccountAccess::new(key, client); @@ -364,7 +364,7 @@ mod tests { #[test] fn test_jwt_initialize_claims() { - let key = service_account_key_from_file(&TEST_PRIVATE_KEY_PATH.to_string()).unwrap(); + let key = service_account_key_from_file(TEST_PRIVATE_KEY_PATH).unwrap(); let scopes = vec!["scope1", "scope2", "scope3"]; let claims = super::init_claims_from_key(&key, &scopes); @@ -384,7 +384,7 @@ mod tests { #[test] fn test_jwt_sign() { - let key = service_account_key_from_file(&TEST_PRIVATE_KEY_PATH.to_string()).unwrap(); + let key = service_account_key_from_file(TEST_PRIVATE_KEY_PATH).unwrap(); let scopes = vec!["scope1", "scope2", "scope3"]; let claims = super::init_claims_from_key(&key, &scopes); let jwt = super::JWT::new(claims); diff --git a/src/storage.rs b/src/storage.rs index 43b203a..673ec4b 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -132,9 +132,9 @@ pub struct DiskTokenStorage { } impl DiskTokenStorage { - pub fn new(location: &String) -> Result { + pub fn new>(location: S) -> Result { let mut dts = DiskTokenStorage { - location: location.clone(), + location: location.as_ref().to_owned(), tokens: HashMap::new(), };