Function if_empty

Source
pub fn if_empty<V, C, Parser, Input>(
    parse: Parser,
) -> impl FnOnce(&mut C, Input) -> Result<()>
where C: Container<V> + ?Sized, Parser: FnOnce(Input) -> Result<Option<V>>,
Expand description

Returns a function checking whether the provided Container::is_empty and if so, setting the value parsed from the provided Input into it.

§Errors

Propagates the error returned by parse function, if any.

§Example

Intended to be used as a predicate in a #[parse] attribute.

#[derive(Default, ParseAttrs)]
struct MyAttributes {
    #[parse(value, fallback = field::if_empty(parse::attr::doc))]
    description: Option<syn::LitStr>,
}