Expand description
Macros to make writing proc-macro crates easy.
This crate provides mainly macros and supporting types and traits
to reduce amount of boilerplate required for working with syn
.
Currently most of the macros are targeted to construct types that then can be parses to configure proc-macro and proc-derive-macro implementation.
easy_token!
- defines new custom token from ident. To be used in other structs.
easy_parse!
- defines struct or enum that can be parsed and peeked from stream.
easy_argument!
- defines struct with a token as a name and the rest to be parsed as-is.
easy_argument_group!
- defines a group of arguments as enum of arguments.
easy_argument_tuple!
- specialized version of easy_argument!
that parses fields starting from 2nd as EasyArgumentField
s inside parenthesis and in any order.
easy_argument_value!
- specialized version of easy_argument!
for 2 field structs. It defines 2nd field as a value that can be parsed after =
token or inside parenthesis.
easy_separated!
- defines struct that parses fields as EasyArgumentField
s in any order. Does not accept trailing punctuation.
easy_terminated!
- defines struct that parses fields as EasyArgumentField
s in any order. Accepts trailing punctuation. Parses whole stream.
easy_attributes!
- defines struct that parses fields as EasyArgumentField
s from a slice of Attribute
s with specified namespace.
EasyArgumentField
is implemented for types defined with easy_token!
, easy_argument!
, easy_argument_tuple!
, easy_argument_value!
and easy_argument_group!
possibly wrapped in Option
or Vec
.
Modules
Macros
- Defines argument structure.
- Defines argument group as enum where each variant is argument type.
- Defines argument structure.
- Defines argument structure with exactly two fields.
- Defines struct and implement
EasyAttributes
for it. - Defines flags and attribute group and fields for them. Flags can be parsed independently. They can be parsed inside attribute that can contain only one flag. They can be parsed inside attribute that accepts a list of flags if provided.
- Defines structure or enum and implements
Parse
for it. - Defines structure and implements
Parse
for it. - Defines structure and implements
Parse
for it. - Defines a type with specified name that implement
EasyToken
and can be parsed from that name ident.
Structs
- Parses inner type braced. Implements
EasyPeek
and peeks opening brace. - Parses inner type bracketed. Implements
EasyPeek
and peeks opening bracket. - Parses inner type parenthesized. Implements
EasyPeek
and peeks opening parenthesis. - Similar to
syn::punctuated::Punctuated
but implementsParse
.
Enums
- Either a value preceded with
=
or parenthesized value. - Expression that may be a constant or a reference to member field. Often used pattern is having attribute that refer to a field or constant expression.
Traits
- Trait for parsable arguments. Arguments have a token as a name that is used for peeking. Name of the argument can be displayed for user in some error cases.
- Trait for types that can be used as fields in easy attributes structures. Fields can parsed and extended when encountered again in parsing stream. If field is never encountered -
EasyArgumentField::missing
value will be used. If attribute type or group is not mandatory - wrap it intoOption
. - Trait that should be implemented for enums of where each variant is an attribute. It is also auto-implemented for all bare attributes. This trait is used to implement
EasyArgumentField
for various types. - Collection of attributes that can be parsed from array of attributes. Can be easily applied to attributes vector parsed by
syn
. - Provides interface for peeking first token before parsing.
- Peekable and parsable single token.