Skip to content

Commit 50fa189

Browse files
committed
fix(schema): now deals with non-objects
These are arrays or HashMaps, which are nested types too. This is used to have custom types of standard vectors or hashmaps, which resolve to NewTypes in Rust.
1 parent a268be2 commit 50fa189

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/mako/lib/schema.mako

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@
77
###################################################################################################################
88
<%def name="new(s, c)">\
99
<%
10-
assert s.type == "object"
1110
markers = schema_markers(s, c)
1211
%>\
1312
<%block filter="rust_doc_comment">\
1413
${doc(s, c)}\
1514
</%block>
1615
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
1716
pub struct ${s.id}\
17+
% if s.type == 'object':
1818
% if 'properties' in s:
1919
{
2020
% for pn, p in s.properties.iteritems():
2121
${p.get('description', 'no description provided') | rust_doc_comment, indent_all_but_first_by(1)}
2222
pub ${mangle_ident(pn)}: ${to_rust_type(s.id, pn, p)},
2323
% endfor
2424
}
25-
% else:
25+
% else: ## it's an empty struct, i.e. struct Foo;
2626
;
27-
% endif
27+
% endif ## 'properties' in s
28+
% else:
29+
(${to_rust_type(s.id, s.id, s)});
30+
% endif ## type == 'object'
2831
2932
% for marker_trait in markers:
3033
impl ${marker_trait} for ${s.id} {}
@@ -72,4 +75,9 @@ ${''.join("* [%s](struct.%s.html) (%s)\n" % (activity_split(a)[2], mb_type(*acti
7275
7376
This type is not used in any activity, and only used as *part* of another schema.
7477
% endif
78+
% if s.type != 'object':
79+
80+
## for some reason, it's not shown in rustdoc ...
81+
The contained type is `${to_rust_type(s.id, s.id, s)}`.
82+
%endif
7583
</%def>

src/mako/lib/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ def iter_nested_properties(prefix, properties):
339339
ns = deepcopy(p)
340340
ns.id = nested_type_name(prefix, pn)
341341
ns[NESTED_TYPE_MARKER] = True
342-
if 'items' in p:
343-
ns.update(p.items.iteritems())
342+
344343
yield ns
344+
345345
for np in iter_nested_properties(prefix + canonical_type_name(pn), ns.properties):
346346
yield np
347347
elif _is_map_prop(p):

0 commit comments

Comments
 (0)