47 lines
778 B
Rust
47 lines
778 B
Rust
use binding::c_enum;
|
|
|
|
|
|
|
|
c_enum!
|
|
{
|
|
/// Test enum is a simple enum testing the
|
|
/// capabilities of creating a C enum.
|
|
enum TestEnum: i32
|
|
{
|
|
/// This is the first item.
|
|
variant One = 1,
|
|
|
|
/// This is the second item.
|
|
variant Two = -2,
|
|
|
|
/// This is the third item.
|
|
variant Three = 3
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pub fn main()
|
|
{
|
|
let cenum: TestEnum;
|
|
|
|
cenum = TestEnum::One;
|
|
println!("Enum value is: {}", cenum);
|
|
|
|
if TestEnum::is_valid_value(-2) == true
|
|
{
|
|
match TestEnum::from_value(-2)
|
|
{
|
|
Some(variant) =>
|
|
{
|
|
println!("Enum value is: {}", variant.to_value());
|
|
}
|
|
|
|
None =>
|
|
{
|
|
panic!("Should not happen since we checked ahead of time.");
|
|
}
|
|
}
|
|
}
|
|
}
|