mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-18 16:34:04 +01:00
Modify GetToken::token.
Change it to accept an iterator of items that can be converted to `String`s rather than an iterator of items that can be referenced as `&str`s. Primarily this allows it to be called with a larger variety of inputs. For example ::std::env::args().skip(1) can now be passed directly to token, where before it would first need to be collected into a vector. Since all implementations unconditionally collected the iterator into a vector this shouldn't have any negative impact on performance and should actually reduce the number of allocations in some uses. It simplifies the signature since the lifetime bounds are no longer required.
This commit is contained in:
@@ -61,15 +61,15 @@ where
|
||||
impl<FD: FlowDelegate + 'static + Send + Clone, C: hyper::client::connect::Connect + 'static>
|
||||
GetToken for InstalledFlow<FD, C>
|
||||
{
|
||||
fn token<'b, I, T>(
|
||||
fn token<I, T>(
|
||||
&mut self,
|
||||
scopes: I,
|
||||
) -> Box<dyn Future<Item = Token, Error = RequestError> + Send>
|
||||
where
|
||||
T: AsRef<str> + Ord + 'b,
|
||||
I: Iterator<Item = &'b T>,
|
||||
T: Into<String>,
|
||||
I: IntoIterator<Item = T>,
|
||||
{
|
||||
Box::new(self.obtain_token(scopes.into_iter().map(|s| s.as_ref().to_string()).collect()))
|
||||
Box::new(self.obtain_token(scopes.into_iter().map(Into::into).collect()))
|
||||
}
|
||||
fn api_key(&mut self) -> Option<String> {
|
||||
None
|
||||
@@ -625,7 +625,7 @@ mod tests {
|
||||
.create();
|
||||
|
||||
let fut = inf
|
||||
.token(vec!["https://googleapis.com/some/scope"].iter())
|
||||
.token(vec!["https://googleapis.com/some/scope"])
|
||||
.and_then(|tok| {
|
||||
assert_eq!("accesstoken", tok.access_token);
|
||||
assert_eq!("refreshtoken", tok.refresh_token);
|
||||
@@ -653,7 +653,7 @@ mod tests {
|
||||
.create();
|
||||
|
||||
let fut = inf
|
||||
.token(vec!["https://googleapis.com/some/scope"].iter())
|
||||
.token(vec!["https://googleapis.com/some/scope"])
|
||||
.and_then(|tok| {
|
||||
assert_eq!("accesstoken", tok.access_token);
|
||||
assert_eq!("refreshtoken", tok.refresh_token);
|
||||
@@ -675,7 +675,7 @@ mod tests {
|
||||
.create();
|
||||
|
||||
let fut = inf
|
||||
.token(vec!["https://googleapis.com/some/scope"].iter())
|
||||
.token(vec!["https://googleapis.com/some/scope"])
|
||||
.then(|tokr| {
|
||||
assert!(tokr.is_err());
|
||||
assert!(format!("{}", tokr.unwrap_err()).contains("invalid_code"));
|
||||
|
||||
Reference in New Issue
Block a user