tl;dr: If an element can contain 0-N child elements, it's not sufficient to specify the child elements in a struct field of type Vec. You have to wrap the Vec in an Option. I found this to be counterintuitive.
I'm not sure if this is a software bug or an issue that should be more clearly explained in the documentation.
Longer:
Consider the following (it's a snippet from an Android resources file):
I can see arguments both ways for this, which is why I'm not sure this is a software bug, but either way, I do think this should be called out in the documentation.
tl;dr: If an element can contain 0-N child elements, it's not sufficient to specify the child elements in a struct field of type
Vec
. You have to wrap theVec
in anOption
. I found this to be counterintuitive.I'm not sure if this is a software bug or an issue that should be more clearly explained in the documentation.
Longer:
Consider the following (it's a snippet from an Android resources file):
resources
contains 0-Nstyle
elements (this example contains > 0, but 0 is possible)style
elements have a mandatoryname
and optionalparent
attributestyle
elements contain 0-Nitem
elements with mandatoryname
attributesMy initial attempt at modelling this was:
My expectation was that any
style
elements with no content (i.e., the first one), would parse correctly, giving aStyle.items
field of length 0.You get an error instead, "
custom: missing field
$value`", which is not very helpful.The fix is to explicitly mark the
items
as optional, by changing theStyle
definition to:I can see arguments both ways for this, which is why I'm not sure this is a software bug, but either way, I do think this should be called out in the documentation.