From 9cafc3720e9a2b31f461a71975cd5e0bf14b039c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 5 May 2015 08:57:13 +0200 Subject: [PATCH] refactor(url): simplify form_urlencode call It's a great simplification and also uses less (if not zero) overhead, finally. Requires url v0.2.33 --- src/device.rs | 17 ++++++++--------- src/refresh.rs | 5 ++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/device.rs b/src/device.rs index 4aaf315..ada40ca 100644 --- a/src/device.rs +++ b/src/device.rs @@ -185,12 +185,12 @@ impl DeviceFlow // note: cloned() shouldn't be needed, see issue // https://github.com/servo/rust-url/issues/81 let req = form_urlencoded::serialize( - [("client_id", client_id), - ("scope", scopes.into_iter() - .map(|s| s.as_ref()) - .intersperse(" ") - .collect::() - .as_ref())].iter().cloned()); + &[("client_id", client_id), + ("scope", scopes.into_iter() + .map(|s| s.as_ref()) + .intersperse(" ") + .collect::() + .as_ref())]); match self.client.borrow_mut().post(FlowType::Device.as_ref()) .header(ContentType("application/x-www-form-urlencoded".parse().unwrap())) @@ -277,11 +277,10 @@ impl DeviceFlow // We should be ready for a new request let req = form_urlencoded::serialize( - [("client_id", &self.id[..]), + &[("client_id", &self.id[..]), ("client_secret", &self.secret), ("code", &self.device_code), - ("grant_type", "http://oauth.net/grant_type/device/1.0")] - .iter().cloned()); + ("grant_type", "http://oauth.net/grant_type/device/1.0")]); let json_str = match self.client.borrow_mut().post(GOOGLE_TOKEN_URL) diff --git a/src/refresh.rs b/src/refresh.rs index aed0837..7b30847 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -66,11 +66,10 @@ impl RefreshFlow } let req = form_urlencoded::serialize( - [("client_id", client_id), + &[("client_id", client_id), ("client_secret", client_secret), ("refresh_token", refresh_token), - ("grant_type", "refresh_token")] - .iter().cloned()); + ("grant_type", "refresh_token")]); let json_str = match self.client.borrow_mut().post(GOOGLE_TOKEN_URL)