proc-macro-workshop:seq-6
审题
// This test case should hopefully be a freebie if all of the previous ones are
// passing. This test demonstrates using the seq macro to construct a const
// array literal.
//
// The generated code would be:
//
// [Proc::new(0), Proc::new(1), ..., Proc::new(255),]
use seq::seq;
const PROCS: [Proc; 256] = {
seq!(N in 0..256 {
[
#(
Proc::new(N),
)*
]
})
};
struct Proc {
id: usize,
}
impl Proc {
const fn new(id: usize) -> Self {
Proc { id }
}
}
fn main() {
assert_eq!(PROCS[32].id, 32);
}
这一关算是一个freebie
,当然,前提是我们之前的[]
也解析了的话。
当然,如果seq-5偷工减料,这一关是不会通过的。
但是使用cursor
的强制匹配,我们不得不枚举了各种情况,这道题就是个弟弟。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: