Skip to content

Commit

Permalink
fix(types): optionals are working once again
Browse files Browse the repository at this point in the history
A bug was introduced which caused nested-types not to be optional
in situations were they should.
  • Loading branch information
Byron committed Mar 11, 2015
1 parent 5d563c8 commit a268be2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
8 changes: 4 additions & 4 deletions gen/youtube3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@
//!
#![feature(core,io)]
// DEBUG !! TODO: Remove this
#![allow(dead_code, unused_mut)]
#![allow(dead_code)]
// 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
#![allow(unused_imports)]
// unused imports in fully featured APIs. Same with unused_mut ... .
#![allow(unused_imports, unused_mut)]


extern crate hyper;
Expand Down Expand Up @@ -1281,7 +1281,7 @@ impl Part for ChannelSectionSnippet {}
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
pub struct ChannelContentDetails {
/// no description provided
pub related_playlists: ChannelContentDetailsRelatedPlaylists,
pub related_playlists: Option<ChannelContentDetailsRelatedPlaylists>,
/// The googlePlusUserId object identifies the Google+ profile ID associated with this channel.
pub google_plus_user_id: Option<String>,
}
Expand Down
23 changes: 10 additions & 13 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,31 +279,28 @@ def nested_type(nt):
return nested_type_name(sn, pn)
return to_rust_type(sn, pn, nt, allow_optionals=False)

# unconditionally handle $ref types, which should point to another schema.
if TREF in t:
tn = t[TREF]
def wrap_type(tn):
if allow_optionals:
return "Option<%s>" % tn
tn = "Option<%s>" % tn
return tn

# unconditionally handle $ref types, which should point to another schema.
if TREF in t:
return wrap_type(t[TREF])
try:
is_pod = True
rust_type = TYPE_MAP[t.type]
if t.type == 'array':
rust_type = "%s<%s>" % (rust_type, nested_type(t))
is_pod = False
return "%s<%s>" % (rust_type, nested_type(t))
elif t.type == 'object':
if _is_map_prop(t):
rust_type = "%s<String, %s>" % (rust_type, nested_type(t))
return "%s<String, %s>" % (rust_type, nested_type(t))
else:
rust_type = nested_type(t)
is_pod = False
return wrap_type(nested_type(t))
elif t.type == 'string' and 'Count' in pn:
rust_type = 'i64'
elif rust_type == USE_FORMAT:
rust_type = TYPE_MAP[t.format]
if is_pod and allow_optionals:
return "Option<%s>" % rust_type
return rust_type
return wrap_type(rust_type)
except KeyError as err:
raise AssertionError("%s: Property type '%s' unknown - add new type mapping: %s" % (str(err), t.type, str(t)))
except AttributeError as err:
Expand Down

0 comments on commit a268be2

Please sign in to comment.