【发布时间】:2017-02-08 07:27:41
【问题描述】:
考虑到这个扩展多个项目的简单宏,它怎么能将宏作为参数?
macro_rules! print_structs {
($($t:ty)*) => ($(
println!("{:?}", TypeId::of::<$t>());
)*)
}
// expands one println per type!
print_structs! { i8 i16 usize String }
如何传入预定义的宏类型?
非工作宏示例:
macro_rules! some_types {
() => {
i8 i16 usize String
}
}
print_structs! { some_types!() }
查看play.rust-lang.org 示例,取消注释UNCOMMENT TO TEST 行以查看问题。
给出错误:macro expansion ignores token `i16` and any following
我还尝试将列表放入要包含的文件中,例如:
print_structs! {
include!("some_types.in")
}
...但是这会产生错误:expected type, found `include!("../struct_list.rs")`
【问题讨论】: