Skip to content

Commit

Permalink
refactor(mbuild+lib): remove map!, better dlg call
Browse files Browse the repository at this point in the history
* map! wasn't used.
* improved delegate calls, using `match` or `delegate.is_some()` to
  get the nicest looking, shortest-possible code
  • Loading branch information
Byron committed Mar 17, 2015
1 parent b90a191 commit 76827ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
14 changes: 0 additions & 14 deletions src/mako/lib.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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()}


Expand Down
17 changes: 7 additions & 10 deletions src/mako/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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() {
Expand Down

0 comments on commit 76827ff

Please sign in to comment.