Given a string (str
), how can one convert that into a TokenStream
in Rust?
I've tried using the quote!
macro.
let str = "4";
let tokens = quote! { let num = #str; }; // #str is a str not i32
The goal here is to generate tokens for some unknown string of code.
let thing = "4";
let tokens = quote! { let thing = #thing }; // i32
or
let thing = ""4"";
let tokens = quote! { let thing = #thing }; // str