是否可以将int转换为生锈的C类枚举?可以从枚举转换为int,但我也想以其他方式进行转换。
enum Type {
FIRST = 1,
SECOND = 2,
THIRD = 3,
}
fn main() {
let x = 3u8 as Type;
println!("{}", x as u8);
}
尝试转换为Type
时出错:
main.rs:8:13: 8:24 error: non-scalar cast: `u8` as `Type`
main.rs:8 let x = 3u8 as Type;
^~~~~~~~~~~
error: aborting due to previous error