| Crates.io | parse-more |
| lib.rs | parse-more |
| version | 0.2.0 |
| created_at | 2025-09-19 20:27:29.704366+00 |
| updated_at | 2025-09-25 07:00:48.204512+00 |
| description | Extension of the `Parse` trait from syn, allowing to parse input from procedural macros directly, without having to create a custom structure and implementing the `Parse` trait on it. |
| homepage | |
| repository | https://github.com/supersurviveur/parse-more |
| max_upload_size | |
| id | 1846991 |
| size | 30,490 |
Parse-more is an extension of the Parse trait from the syn crate, allowing to parse input from procedural macros directly, without having to create a custom structure and implementing the Parse trait on it.
It provides classic syn macros and functions variant, using the ParseMore trait instead.
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.value();
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)
}
}
Add to your Cargo.toml file:
[dependencies]
parse-more = "0.2"
Contributions are welcome! Open an issue or a pull request.
This project is licensed under the MIT License.