rust学习(9)-关于strum crate 的简单使用

1 #[strum(to_string = “XXX”)]

use strum::ToString;
    #[derive(ToString)]
    pub enum ProjectName {
        #[strum(to_string = "probe")]
        Probe,
        #[strum(to_string = "nspm")]
        Nspm,
        #[strum(to_string = "all")]
        All,
    }

    #[test]
    fn test2() {
        let a = ProjectName::Probe;
        let s = a.to_string();
        println!("{}", s);
    }
/*
output
probe
*/

猜你喜欢

转载自blog.csdn.net/qq_40642465/article/details/120993693