Crate derive_attribute

source ·
Expand description

A set of macros to automatically deserialize standard attributes

Getting Started

Make sure a Syn version is selected in features: features = ["syn_2"]

Our attribute type is declared in a procedural macro crate:

#[derive(Attribute)]
#[attr(name = "my_attr")] // We set the attribute name to 'my_attr'
struct MyAttribute {      // Note: The attribute name will be the struct name in snake_case by default
    name: String,
    // wrapping a type in an option will make it optional
    list: Option<NestedList>, // deserializes a meta list named list i.e. list(num = 1)

    // booleans are always optional
    is_selected: bool,
}
    #[derive(List)]
    pub struct NestedList {
        num: Option<u8>
    }

It can then be used to parse the following attribute using the from_attrs method:

#[my_attr(name = "some_name", is_selected)]

For a more extensive guide check out the github.

Modules

Structs

Enums

Traits

  • Represents a struct that can be deserialized from Syn attributes.
  • Combines an argument with a previously stored instance.
  • Gets the Span of Syn metadata
  • Represents a Syn version and how it can parse attribute data into values
  • A trait for deserializing Syn metadata.
    Its recommended that you use the CustomArgFromMeta trait for deserializing simple arguments.

Functions

Derive Macros