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§
- easy_
argument - Defines argument structure.
- easy_
argument_ group - Defines argument group as enum where each variant is argument type.
- easy_
argument_ tuple - Defines argument structure.
- easy_
argument_ value - Defines argument structure with exactly two fields.
- easy_
attributes - Defines struct and implement
EasyAttributes
for it. - easy_
flags - 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.
- easy_
parse - Defines structure or enum and implements
Parse
for it. - easy_
separated - Defines structure and implements
Parse
for it. - easy_
terminated - Defines structure and implements
Parse
for it. - easy_
token - Defines a type with specified name that implement
EasyToken
and can be parsed from that name ident.
Structs§
- Easy
Braced - Parses inner type braced.
Implements
EasyPeek
and peeks opening brace. - Easy
Bracketed - Parses inner type bracketed.
Implements
EasyPeek
and peeks opening bracket. - Easy
Parenthesized - Parses inner type parenthesized.
Implements
EasyPeek
and peeks opening parenthesis. - Easy
Separated - Similar to
syn::punctuated::Punctuated
but implementsParse
and optionallyEasyPeek
. - Easy
Terminated - Similar to
syn::punctuated::Punctuated
but implementsParse
.
Enums§
- Easy
Maybe - Similar to
Option
but implementsParse
whenT
implementsEasyPeek
- Easy
SubArgument - Either a value preceded with
=
or parenthesized value. - Reference
Expr - 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§
- Easy
Argument - 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.
- Easy
Argument Field - 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
. - Easy
Argument Group - 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. - Easy
Attributes - Collection of attributes that can be parsed from array of attributes.
Can be easily applied to attributes vector parsed by
syn
. - Easy
Peek - Provides interface for peeking first token before parsing.
- Easy
Token - Peekable and parsable single token.