feat(derive): add the non_empty
attribute to children(...)
#32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @tailhook !
This is a slightly bigger change than my other PR, but fundamentally just enables me to add a
non_empty
tag to#[knuffel(children(...))]
attributes, guaranteeing that at least one child is present. At the moment, Knuffel is happy parsing nodes with no children and simply returning an empty vector, but that's different from the behavior of#[knuffel(child)]
which (sensibly) errors when no child is present. You can usechild
to parse exactly one child, you can usechildren
for zero-or-more, but there is currently no way to parse one-or-more. This PR effectively adds that ability.I've not written anything up in the documentation just yet (I wanted to be sure you were happy with this feature as is, before writing up anything), but here is a basic example...
Attempting to parse this KDL (with all of the children commented out):
Using this struct:
Now returns an error where it didn't before:
Let me know what you think! It's my first time touching proc_macros, so I'm sure there is plenty of learning for me to do!
Hope you're well,
Brooks