如工厂产线上机器运行状态,如下定义泛型枚举来记录各个设备的运行状况:
#[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); }
运行结果: