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 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!