I am experimenting with Rust procedural macros.
I would like to be able to create a macro that would be used to generate JNI invocation boilerplate. Something like
jni_method!{com.purplefrog.rust_callable.Widget, fn echo_str(&str)->String}
I have the following code so far (playground):
#[macro_use]
extern crate syn; // 1.0.33
use syn::parse::{Parse, ParseStream};
use syn::Signature;
struct Arguments {
name: proc_macro2::Ident,
signature: Signature,
}
impl Parse for Arguments {
fn parse(tokens: ParseStream) -> Result<Arguments, syn::Error> {
let name: proc_macro2::Ident = tokens.parse()?;
let comma: Token![,] = tokens.parse()?;
let signature: Signature = //tokens.parse()?;
syn::item::parsing::parse_signature(tokens)?;
Ok(Arguments {
name: name,
signature,
})
}
}
Unfortunately, the parse_signature
call is in error:
error[E0603]: module `item` is private
--> src/lib.rs:17:18
|
17 | syn::item::parsing::parse_signature(tokens)?;
| ^^^^ private module
|
note: the module `item` is defined here
--> /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.33/src/lib.rs:363:1
|
363 | mod item;
| ^^^^^^^^^
What is the proper way to parse a Signature
from a ParseStream
?