Module parsing

Source
Expand description

This module defines the traits defining how parsing works.

attribute-derive reuses the same traits for nested values and the root attribute, this is why all traits in this module are named Attribute*.

FromAttr

Main entry point. Derived via macro. Anything that can be parsed from one or multiple attributes.

AttributeNamed

Values that can be parsed named, e.g. name(<value>), name = <value>, name (as flag).

This is the default parsing mode used for fields in derived FromAttr implementations.

AttributePositional

Values that can be parsed positionally, i.e., without a name, e.g. "literal", a + b, true.

When deriving FromAttr this is enabled via putting #[attr(positional)] on the field.

impl <T: AttributeValue> FromAttr for T
impl <T: AttributeValue> AttributeNamed for T
impl <T: AttributeValue + PositionalValue> AttributePositional for T

AttributeValue

Any attribute that has the concept of a value, e.g., "positional", meta(<value>), key = <value>.

PositionalValue

Empty marker trait, defining which AttributeValue implement AttributePositional.
impl <T: AttributeMeta> AttributeValue for T

AttributeMeta

Values in function or meta style attributes, i.e., meta(<value>).

Structs§

Named
Helper struct to hold a value and the ident of its property.
SpannedValue
Helper struct to hold a value and the corresponding range.

Traits§

AttributeBase
Utility crate holding Self::Partial used in most attribute traits, i.e., FromAttr, AttributeValue, AttributePositional, …
AttributeMeta
Trait implementing parsing for <function>(<like>) attributes.
AttributeNamed
Values that can be parsed named, e.g. <name>(<value>), <name> = <value>, <name> (as flag).
AttributePeekable
Trait implemented for attributes that can be parsed optionally as a positional argument, and the requirement for Option<T> to implement AttributePositional.
AttributePositional
Values that can be parsed positionally, i.e., without a name, e.g. "literal", a + b, true.
AttributeValue
Any values that can be parsed in an attribute input.
PositionalValue
Marker trait that enables the blanket implementation of AttributePositional for AttributeValue.

Functions§

parse_name
Parses the name, if it matches returns Some(name) and removes the name from input, if None it does not modify the input.