From a268be27d2123a77259fa1d7d1f831c7e72c4459 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 11 Mar 2015 10:32:18 +0100 Subject: [PATCH] fix(types): optionals are working once again A bug was introduced which caused nested-types not to be optional in situations were they should. --- gen/youtube3/src/lib.rs | 8 ++++---- src/mako/lib/util.py | 23 ++++++++++------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/gen/youtube3/src/lib.rs b/gen/youtube3/src/lib.rs index da3c5734f69..0dec81ea29f 100644 --- a/gen/youtube3/src/lib.rs +++ b/gen/youtube3/src/lib.rs @@ -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; @@ -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, /// The googlePlusUserId object identifies the Google+ profile ID associated with this channel. pub google_plus_user_id: Option, } diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index bb9527ad6b3..4b43007847e 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -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" % (rust_type, nested_type(t)) + return "%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: