imp: accept any string-like parameter

Use the power of the `AsRef` trait to take generic parameters for
several API functions. This makes the API more ergonomic because the
callers may pass in static `str` slices or references to owned `String`s
or even more exotic things like a `Cow`, all based on their particular
situation.

Update the tests and examples to use the most natural types they have
available.

Fixes #77. No existing code should break, as `&String` implements
`AsRef<str>` and `AsRef<Path>`
This commit is contained in:
Lyle Mantooth
2019-04-03 09:01:28 -04:00
parent de57b8fbdf
commit 108162fcf8
9 changed files with 24 additions and 16 deletions

View File

@@ -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(

View File

@@ -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);