2024-01-03 03:22:36 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2023-04-17 07:39:12 +00:00
|
|
|
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());
|
|
|
|
|
}
|