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);
}
运行结果:

------------------------------------
承接
**视觉检测软件开发及调试
**工业软件开发
**上位机软件开发
wechat:luoran2024
qq:565934058
email:taoyuansu@qq.com
海量教育资源及影视资源下载
微信公众号:EFun科技
------------------------------------

浙公网安备 33010602011771号