mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 19:33:23 +00:00
Add crate int-to-c-enum
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
aec46295c4
commit
6ecc7dc557
22
services/libs/int-to-c-enum/tests/regression.rs
Normal file
22
services/libs/int-to-c-enum/tests/regression.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use int_to_c_enum::TryFromInt;
|
||||
|
||||
#[derive(TryFromInt, Debug, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
enum Color {
|
||||
Red = 1,
|
||||
Blue = 2,
|
||||
Green = 3,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conversion() {
|
||||
let color = Color::try_from(1).unwrap();
|
||||
println!("color = {color:?}");
|
||||
assert!(color == Color::Red);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_value() {
|
||||
let color = Color::try_from(4);
|
||||
assert!(color.is_err());
|
||||
}
|
Reference in New Issue
Block a user