Skip to content

Commit

Permalink
fix(doit): remove BorrowMut until it's cleared
Browse files Browse the repository at this point in the history
See stackoverflow at http://goo.gl/f27zJkj.

Now we can actually call out client and move on with handling the result
  • Loading branch information
Byron committed Mar 16, 2015
1 parent 9a58b0b commit 1349c78
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 37 deletions.
18 changes: 7 additions & 11 deletions src/mako/lib.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%
from util import (new_context, rust_comment, rust_doc_comment,
rust_module_doc_comment, rb_type, hub_type, mangle_ident, hub_type_params_s,
hub_type_bounds, rb_type_params_s, find_fattest_resource)
hub_type_bounds, rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS)
c = new_context(schemas, resources)
hub_type = hub_type(c.schemas, util.canonical_name())
Expand All @@ -19,9 +19,9 @@
<%block filter="rust_module_doc_comment">\
${lib.docs(c)}
</%block>
#![feature(core,io)]
#![feature(core,io, old_io)]
// DEBUG !! TODO: Remove this
#![allow(dead_code)]
#![allow(dead_code, deprecated)]
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
// unused imports in fully featured APIs. Same with unused_mut ... .
Expand All @@ -37,8 +37,6 @@ extern crate url;
pub mod cmn;

use std::collections::HashMap;
use std::marker::PhantomData;
use std::borrow::BorrowMut;
use std::cell::RefCell;
use std::default::Default;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -84,21 +82,19 @@ ${lib.scope_enum()}
${lib.hub_usage_example(c)}\
</%block>
pub struct ${hub_type}${ht_params} {
client: RefCell<C>,
client: RefCell<hyper::Client<NC>>,
auth: RefCell<A>,
_m: PhantomData<NC>
}

impl<'a, C, NC, A> Hub for ${hub_type}${ht_params} {}
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> Hub for ${hub_type}${ht_params} {}

impl<'a, C, NC, A> ${hub_type}${ht_params}
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params}
where ${', '.join(hub_type_bounds())} {

pub fn new(client: C, authenticator: A) -> ${hub_type}${ht_params} {
pub fn new(client: hyper::Client<NC>, authenticator: A) -> ${hub_type}${ht_params} {
${hub_type} {
client: RefCell::new(client),
auth: RefCell::new(authenticator),
_m: PhantomData,
}
}

Expand Down
24 changes: 1 addition & 23 deletions src/mako/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ ${self.usage(resource, method, m, params, request_value, parts)}\
</%block>
pub struct ${ThisType}
where NC: 'a,
C: 'a,
A: 'a, {
hub: &'a ${hub_type_name}${hub_type_params_s()},
Expand Down Expand Up @@ -430,7 +429,7 @@ else {
url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice()))));
loop {
match self.hub.client.borrow_mut().borrow_mut().request(Method::Extension("${m.httpMethod}".to_string()), &url)
match self.hub.client.borrow_mut().request(Method::Extension("${m.httpMethod}".to_string()), url.as_slice())
.header(UserAgent("google-api-rust-client/${cargo.build_version}".to_string()))
% if request_value:
.header(ContentType(Mime(TopLevel::Application, SubLevel::Json, Default::default())))
Expand All @@ -457,33 +456,12 @@ else {
}
}
% if response_schema:
let response: ${response_schema.id} = Default::default();
% else:
let response = ();
% endif
## let mut params: Vec<(String, String)> = Vec::with_capacity
## // 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_slice())
## .intersperse(" ")
## .collect::<String>()
## .as_slice())].iter().cloned());
## match self.client.borrow_mut().post(FlowType::Device.as_slice())
## .header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
## .body(req.as_slice())
## .send() {
## Err(err) => {
## return RequestResult::Error(err);
## }
cmn::Result::Success(response)
}
Expand Down
1 change: 0 additions & 1 deletion src/mako/lib/rbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ let rb = hub.${mangle_ident(resource)}();
</%block>
pub struct ${ThisType}
where NC: 'a,
C: 'a,
A: 'a, {
hub: &'a ${hub_type_name}${hub_type_params_s()},
Expand Down
3 changes: 1 addition & 2 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
'%': 1,
}

HUB_TYPE_PARAMETERS = ('C', 'NC', 'A')
HUB_TYPE_PARAMETERS = ('NC', 'A')

# ==============================================================================
## @name Filters
Expand Down Expand Up @@ -732,7 +732,6 @@ def hub_type_params_s():
# return a list of where statements to server as bounds for the hub.
def hub_type_bounds():
return ['NC: hyper::net::NetworkConnector',
"C: BorrowMut<hyper::Client<NC>> + 'a",
'A: oauth2::GetToken']

# return list of type bounds required by method builder
Expand Down

0 comments on commit 1349c78

Please sign in to comment.