proc-macro-workshop:sorted-8
审题
// There is one other common type of pattern that would be nice to support --
// the wildcard or underscore pattern. The #[sorted] macro should check that if
// a wildcard pattern is present then it is the last one.
use sorted::sorted;
#[sorted]
pub enum Conference {
RustBeltRust,
RustConf,
RustFest,
RustLatam,
RustRush,
}
impl Conference {
#[sorted::check]
pub fn region(&self) -> &str {
use self::Conference::*;
#[sorted]
match self {
RustFest => "Europe",
RustLatam => "Latin America",
_ => "elsewhere",
}
}
}
fn main() {}
看代码不太清楚,但是看见提示wildcard
那就了然于胸了。
我们需要支持
wildcard
,也就是_
。
一切都在sorted-5,我们已然支持。
不过有一点容易忽略的是,_
排序本身就低于英文字母,所以才能保证直接排序。
如果使用的不是_
,那还需要额外操作。
sorted
真 · 完结
本作品采用《CC 协议》,转载必须注明作者和本文链接