call2-for-syn
This library provides a call2
function that sits somewhere in-between syn
's parse2
and ParseBuffer::call
: It lets you conveniently apply a parser function to a proc-macro2
token stream, for example from a quote!
.
Example
use {
call2_for_syn::call2,
quote::quote,
syn::{Ident, Token},
};
let (hello, world) = call2::<syn::Result<_>, _>(
quote!(Hello world!),
|input| {
let hello: Ident = input.parse()?;
let world: Ident = input.parse()?;
input.parse::<Token![!]>()?;
Ok((hello, world))
},
)?;
assert_eq!(format!("{}", hello), "Hello");
assert_eq!(format!("{}", world), "world");