Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a268be2

Browse files
committed
fix(types): optionals are working once again
A bug was introduced which caused nested-types not to be optional in situations were they should.
1 parent 5d563c8 commit a268be2

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

gen/youtube3/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@
120120
//!
121121
#![feature(core,io)]
122122
// DEBUG !! TODO: Remove this
123-
#![allow(dead_code, unused_mut)]
123+
#![allow(dead_code)]
124124
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
125125
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
126-
// unused imports in fully featured APIs
127-
#![allow(unused_imports)]
126+
// unused imports in fully featured APIs. Same with unused_mut ... .
127+
#![allow(unused_imports, unused_mut)]
128128

129129

130130
extern crate hyper;
@@ -1281,7 +1281,7 @@ impl Part for ChannelSectionSnippet {}
12811281
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
12821282
pub struct ChannelContentDetails {
12831283
/// no description provided
1284-
pub related_playlists: ChannelContentDetailsRelatedPlaylists,
1284+
pub related_playlists: Option<ChannelContentDetailsRelatedPlaylists>,
12851285
/// The googlePlusUserId object identifies the Google+ profile ID associated with this channel.
12861286
pub google_plus_user_id: Option<String>,
12871287
}

src/mako/lib/util.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,31 +279,28 @@ def nested_type(nt):
279279
return nested_type_name(sn, pn)
280280
return to_rust_type(sn, pn, nt, allow_optionals=False)
281281

282-
# unconditionally handle $ref types, which should point to another schema.
283-
if TREF in t:
284-
tn = t[TREF]
282+
def wrap_type(tn):
285283
if allow_optionals:
286-
return "Option<%s>" % tn
284+
tn = "Option<%s>" % tn
287285
return tn
286+
287+
# unconditionally handle $ref types, which should point to another schema.
288+
if TREF in t:
289+
return wrap_type(t[TREF])
288290
try:
289-
is_pod = True
290291
rust_type = TYPE_MAP[t.type]
291292
if t.type == 'array':
292-
rust_type = "%s<%s>" % (rust_type, nested_type(t))
293-
is_pod = False
293+
return "%s<%s>" % (rust_type, nested_type(t))
294294
elif t.type == 'object':
295295
if _is_map_prop(t):
296-
rust_type = "%s<String, %s>" % (rust_type, nested_type(t))
296+
return "%s<String, %s>" % (rust_type, nested_type(t))
297297
else:
298-
rust_type = nested_type(t)
299-
is_pod = False
298+
return wrap_type(nested_type(t))
300299
elif t.type == 'string' and 'Count' in pn:
301300
rust_type = 'i64'
302301
elif rust_type == USE_FORMAT:
303302
rust_type = TYPE_MAP[t.format]
304-
if is_pod and allow_optionals:
305-
return "Option<%s>" % rust_type
306-
return rust_type
303+
return wrap_type(rust_type)
307304
except KeyError as err:
308305
raise AssertionError("%s: Property type '%s' unknown - add new type mapping: %s" % (str(err), t.type, str(t)))
309306
except AttributeError as err:

0 commit comments

Comments
 (0)