Rust--枚举泛型

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#[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);
}

 运行结果:

 

posted @   echo-efun  阅读(130)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示