-
-
Notifications
You must be signed in to change notification settings - Fork 79
Closed
Labels
Description
A common pattern (seen in #367, among other places) is to want to have a field that supports multiple formats: The simple word form, the key-value form, or a sub-object "list" form.
The from_word
override allows someone to derive FromMeta
while specifying how that format should work, but there is no clean override for the key-value form.
The example in #367 would become:
#[derive(Default, FromMeta)]
#[darling(
from_word = Default::default,
from_expr = |expr| Ok(Self { value: Some(expr.clone()), ..Default::default() })
)]
struct ErrorPolicy {
warn: Flag,
value: Option<syn::Expr>
}
That is more concise, as it avoids duplication of the struct declaration to get a derived impl.
Veetaha