Expand description
§parse-more
Parse-more is an extension of the syn::parse::Parse trait from the syn crate, allowing to parse input from procedural macros directly, without having to create a custom structure and implementing the syn::parse::Parse trait on it.
It provides classic syn macros and functions variant, using the ParseMore trait instead.
§Example
use quote::quote;
use parse_more::{parse_more_macro_input, Concat, Braced};
use proc_macro::TokenStream;
use syn::{Expr, Ident, Token, punctuated::Punctuated};
#[proc_macro]
pub fn complex_args(input: TokenStream) -> TokenStream {
let content = parse_more_macro_input!(
input as Punctuated<Concat<Ident, Token![=>], Braced<(Ident, Expr)>>, Token![,]>
);
content
.into_iter()
.map(|concat| {
// Second item is discarded (it's the => arrow)
let (ident, _, Braced((other_ident, literal))) = concat.into();
quote! {
println!("{}: {} versus other type {}", #literal, (-1i8) as #ident, (-1i8) as #other_ident);
}
})
.collect::<proc_macro2::TokenStream>()
.into()
}
And then :
complex_args! {
u8 => {
(i8, "u8 integer")
},
u16 => {
(i16, "u16 integer")
},
Foo => {
(Bar, 8 + 42)
}
}
Modules§
- syn_
types - Implementation of the ParseMore trait for every types from the syn crates implementing syn::parse::Parse.
Macros§
- parse_
more_ auto_ impl - This macro auto-implements the ParseMore traits on its arguments, which MUST implement the syn::parse::Parse trait. It allows using custom types inside of any parse-more macros/functions.
- parse_
more_ macro_ input - Same as the syn::parse_macro_input macro, but using the ParseMore trait.
- parse_
more_ quote - Same as the syn::parse_quote macro, but using the ParseMore trait.
Structs§
- Braced
- Parse an item surrounded by braces.
- Bracketed
- Parse an item surrounded by brackets.
- Concat
- Parse successive items.
- Invalid
- Parse an item surrounded by brackets.
- Parenthesized
- Parse an item surrounded by parenthesis.
- Parse
More Wrapper - This wrapper implements syn::parse::Parse when T implements ParseMore. It permits to use this wrapper and a type implementing ParseMore in a parsing function from syn.
Enums§
- Either
- Parse an item in a given list. If multiple types can be parsed, the first one is chosen.
Traits§
- Parse
More - Parsing interface implemented by all types from the syn crate which already implement syn::parse::Parse, and some others usefull ones. Use the parse_more_auto_impl macros to easily implement ParseMore on a type which already implement syn::parse::Parse.
Functions§
- parse2_
more - Same as the syn::parse2 function, but using the ParseMore trait.
- parse_
more - Same as the syn::parse() function, but using the ParseMore trait.
- parse_
more_ str - Same as the syn::parse_str function, but using the ParseMore trait.
Attribute Macros§
- filler
- Re-export proc macro. Parse an additionnal type between two struct fields.
- parse_
more - Re-export proc macro. Auto-implements the parse_more::ParseMore trait on an item.