Crate proc_easy

Source
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 EasyArgumentFields 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 EasyArgumentFields in any order. Does not accept trailing punctuation.

easy_terminated! - defines struct that parses fields as EasyArgumentFields in any order. Accepts trailing punctuation. Parses whole stream.

easy_attributes! - defines struct that parses fields as EasyArgumentFields from a slice of Attributes 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§

examples

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§

EasyBraced
Parses inner type braced. Implements EasyPeek and peeks opening brace.
EasyBracketed
Parses inner type bracketed. Implements EasyPeek and peeks opening bracket.
EasyParenthesized
Parses inner type parenthesized. Implements EasyPeek and peeks opening parenthesis.
EasySeparated
Similar to syn::punctuated::Punctuated but implements Parse and optionally EasyPeek.
EasyTerminated
Similar to syn::punctuated::Punctuated but implements Parse.

Enums§

EasyMaybe
Similar to Option but implements Parse when T implements EasyPeek
EasySubArgument
Either a value preceded with = or parenthesized value.
ReferenceExpr
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§

EasyArgument
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.
EasyArgumentField
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 into Option.
EasyArgumentGroup
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.
EasyAttributes
Collection of attributes that can be parsed from array of attributes. Can be easily applied to attributes vector parsed by syn.
EasyPeek
Provides interface for peeking first token before parsing.
EasyToken
Peekable and parsable single token.