I'm trying to follow this post to get my feet wet with proc macros (Can a procedural macro be debugged as a function?)
I came up with this to just to get a feel for how it all works:
extern crate proc_macro;
use proc_macro2::TokenStream;
use std::str::FromStr;
use syn;
use quote;
fn main() {
let ts = TokenStream::from_str("fn foo() {}").unwrap();
let _ts_str = ts.to_string();
let parsed = syn::parse_macro_input!(ts);
}
But when I run in the Playground I get this error:
error[E0308]: mismatched types
--> src/main.rs:10:18
|
10 | let parsed = syn::parse_macro_input!(ts);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected struct `proc_macro::TokenStream`, found struct `TokenStream2`
| arguments to this function are incorrect
|
note: function defined here
--> /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.103/src/parse_macro_input.rs:138:8
|
138 | pub fn parse<T: ParseMacroInput>(token_stream: TokenStream) -> Result<T> {
| ^^^^^
= note: this error originates in the macro `$crate::parse_macro_input` which comes from the expansion of the macro `syn::parse_macro_input` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> src/main.rs:10:18
|
10 | let parsed = syn::parse_macro_input!(ts);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `proc_macro::TokenStream`
|
= note: this error originates in the macro `$crate::parse_macro_input` which comes from the expansion of the macro `syn::parse_macro_input` (in Nightly builds, run with -Z macro-backtrace for more info)
I'm having trouble understanding what is going on, and could use some help. I've tried various typecasting but nothing seems to work.
I know as a Rust newbie I'm kinda jumping into the deep end of the pool here, but it is somewhat unavoidable. I'm running into little issues that I think will be barriers to getting Rust accepted for our application, and I'm trying to forge a path with as little friction as possible to convince our team (and myself) to move away from C/C++ in our embedded application. So I appreciate the help and patience here.