我最近开始尝试使用稳定的程序宏。虽然我很快就理解了大部分内容,但我没有找到在宏中实际访问自定义属性的方法。 我找到的唯一有用的来源是this chapter of the Rust book。
我目前坚持:
#[proc_macro_derive(Foo, attributes(Boo, Goo))]
pub fn foo(input: TokenStream) -> TokenStream {
// Construct a string representation of the type definition
let s = input.to_string();
// Parse the string representation
let ast = syn::parse_derive_input(&s).unwrap();
// Build the impl
let gen = impl_object(&ast);
// Return the generated impl
gen.parse().unwrap()
}
和
#[derive(Foo)]
#[Boo = true]
pub struct Ruu { /* .. */ }
如何在宏中使用我的自定义属性?