Skip to content

Commit

Permalink
fix(types): make recursive types possible
Browse files Browse the repository at this point in the history
Must be `Option<Box<T>>` now, whereas a simple `Box<T>` worked
previously. Anyway, serde can't decode/encode Boxes yet, so
plus1 was removed from the list of APIs to build.

Related to #34
  • Loading branch information
Byron committed Mar 20, 2015
1 parent 0823dec commit 8d9f175
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions etc/api/api-list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ api:
- v2
pagespeedonline:
- v2
plus:
- v1
# Does not build yet, see serde issue: https://github.com/erickt/rust-serde/issues/45
# plus:
# - v1
plusdomains:
- v1
prediction:
Expand Down
8 changes: 4 additions & 4 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _assure_unique_type_name(schemas, tn):
# pn = property name
# t = type dict
# NOTE: In case you don't understand how this algorithm really works ... me neither - THE AUTHOR
def to_rust_type(schemas, sn, pn, t, allow_optionals=True):
def to_rust_type(schemas, sn, pn, t, allow_optionals=True, _is_recursive=False):
def nested_type(nt):
if 'items' in nt:
nt = nt.items
Expand All @@ -301,7 +301,7 @@ def nested_type(nt):
assert(is_nested_type_property(nt))
# It's a nested type - we take it literally like $ref, but generate a name for the type ourselves
return _assure_unique_type_name(schemas, nested_type_name(sn, pn))
return to_rust_type(schemas, sn, pn, nt, allow_optionals=False)
return to_rust_type(schemas, sn, pn, nt, allow_optionals=False, _is_recursive=True)

def wrap_type(tn):
if allow_optionals:
Expand All @@ -314,8 +314,8 @@ def wrap_type(tn):
# which is fine for now. 'allow_optionals' implicitly restricts type boxing for simple types - it
# usually is on on the first call, and off when recursion is involved.
tn = t[TREF]
if allow_optionals and tn == sn:
tn = 'Box<%s>' % unique_type_name(tn)
if not _is_recursive and tn == sn:
tn = 'Option<Box<%s>>' % unique_type_name(tn)
return wrap_type(tn)
try:
rust_type = TYPE_MAP[t.type]
Expand Down

0 comments on commit 8d9f175

Please sign in to comment.