From 76827ff6659d33b7b9430e4971a7189fa0d23798 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 17 Mar 2015 21:56:34 +0100 Subject: [PATCH] refactor(mbuild+lib): remove map!, better dlg call * map! wasn't used. * improved delegate calls, using `match` or `delegate.is_some()` to get the nicest looking, shortest-possible code --- src/mako/lib.rs.mako | 14 -------------- src/mako/lib/mbuild.mako | 17 +++++++---------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/mako/lib.rs.mako b/src/mako/lib.rs.mako index 59e216ad144..17ba29c30e3 100644 --- a/src/mako/lib.rs.mako +++ b/src/mako/lib.rs.mako @@ -54,20 +54,6 @@ use cmn::{Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegat // UTILITIES ### // ############ -/// This macro is advertised in the documentation, which is why we deliver it as well -#[macro_export] -macro_rules! map( - { $($key:expr => $value:expr),+ } => { - { - let mut m = ::std::collections::HashMap::new(); - $( - m.insert($key, $value); - )+ - m - } - }; -); - ${lib.scope_enum()} diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index 19583db6edc..b83e5bc2f9a 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -592,8 +592,9 @@ else { } let auth_header = hyper::header::Authorization(token.unwrap().access_token); % endif - if ${delegate}.is_some() { - ${delegate_call}.pre_request("${m.id}"); + match ${delegate} { + Some(ref mut d) => d.pre_request("${m.id}"), + None => {} } match ${client}.request(hyper::method::Method::Extension("${m.httpMethod}".to_string()), url.as_slice()) .header(hyper::header::UserAgent("google-api-rust-client/${cargo.build_version}".to_string())) @@ -607,16 +608,12 @@ else { .send() { Err(err) => { if ${delegate}.is_some() { - match ${delegate_call}.http_error(&err) { - oauth2::Retry::Abort => return cmn::Result::HttpError(err), - oauth2::Retry::After(d) => { - sleep(d); - continue; - } + if let oauth2::Retry::After(d) = ${delegate_call}.http_error(&err) { + sleep(d); + continue; } - } else { - return cmn::Result::HttpError(err); } + return cmn::Result::HttpError(err) } Ok(mut res) => { if !res.status.is_success() {