2016-03-28 21:08:08 -06:00
|
|
|
enum Foo {
|
|
|
|
Bar = 42,
|
|
|
|
Baz,
|
|
|
|
Quux = 100,
|
|
|
|
}
|
|
|
|
|
2016-05-08 19:49:07 -06:00
|
|
|
enum Signed {
|
|
|
|
Bar = -42,
|
|
|
|
Baz,
|
|
|
|
Quux = 100,
|
|
|
|
}
|
|
|
|
|
2016-03-28 21:08:08 -06:00
|
|
|
fn foo() -> [u8; 3] {
|
|
|
|
[Foo::Bar as u8, Foo::Baz as u8, Foo::Quux as u8]
|
|
|
|
}
|
|
|
|
|
2016-05-08 19:49:07 -06:00
|
|
|
fn signed() -> [i8; 3] {
|
|
|
|
[Signed::Bar as i8, Signed::Baz as i8, Signed::Quux as i8]
|
|
|
|
}
|
|
|
|
|
2016-03-28 21:08:08 -06:00
|
|
|
fn unsafe_match() -> bool {
|
|
|
|
match unsafe { std::mem::transmute::<u8, Foo>(43) } {
|
|
|
|
Foo::Baz => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 10:34:14 +02:00
|
|
|
|
2016-04-22 14:38:46 +02:00
|
|
|
fn main() {
|
2016-05-09 21:53:20 -06:00
|
|
|
assert_eq!(foo(), [42, 43, 100]);
|
|
|
|
assert_eq!(signed(), [-42, -41, 100]);
|
2016-04-22 14:38:46 +02:00
|
|
|
assert!(unsafe_match());
|
|
|
|
}
|