Rust--枚举泛型

如工厂产线上机器运行状态,如下定义泛型枚举来记录各个设备的运行状况:

#[derive(Debug)]
enum RunStatus<O,N>{
    OK(O,N),
    NG(O,N),
}


fn main(){
    let machine1 = RunStatus::OK(String::from("2021-01-07 15:14:22"),String::from("software restart success"));

    let machine2 = RunStatus::NG(String::from("2021-01-01 01:11:12"),String::from("plc cannot conect to PC1"));


    println!("machine1 status---{:#?}",machine1);
    println!("machine2 status---{:#?}",machine2);
}

 运行结果:

Rust--枚举泛型

 

上一篇:Rust中的变量隐藏


下一篇:EF6数据迁移