5 #[derive(PartialEq, Eq)]
8 #[derive(PartialEq, Eq)]
16 #[derive(PartialEq, Eq)]
18 bar
: Option
<Direction
>,
22 #[derive(PartialEq, Eq)]
23 enum EnumWithStructVariants
{
30 const TRUE_TRUE
: (bool
, bool
) = (true, true);
31 const NONE
: Option
<Direction
> = None
;
32 const EAST
: Direction
= Direction
::East
;
33 const NEW_FALSE
: NewBool
= NewBool(false);
34 const STATIC_FOO
: Foo
= Foo { bar: Some(Direction::South), baz: NEW_FALSE }
;
35 const VARIANT2_NORTH
: EnumWithStructVariants
= EnumWithStructVariants
::Variant2
{
36 dir
: Direction
::North
};
39 #[derive(Copy, Clone, PartialEq, Eq)]
40 pub struct InputState(usize);
42 pub const RELEASE
: InputState
= InputState(0);
43 pub const PRESS
: InputState
= InputState(1);
44 pub const REPEAT
: InputState
= InputState(2);
48 fn action_to_str(state
: glfw
::InputState
) -> &'
static str {
49 use glfw
::{RELEASE, PRESS, REPEAT}
;
51 RELEASE
=> { "Released" }
52 PRESS
=> { "Pressed" }
53 REPEAT
=> { "Repeated" }
58 assert_eq
!(action_to_str(glfw
::RELEASE
), "Released");
59 assert_eq
!(action_to_str(glfw
::PRESS
), "Pressed");
60 assert_eq
!(action_to_str(glfw
::REPEAT
), "Repeated");
64 const VAL
: [u8; 1] = [0];
66 VAL
=> unreachable
!(),
72 type Foo
= (i32, i32);
73 const ON
: Foo
= (1, 1);
74 const OFF
: Foo
= (0, 0);
77 OFF
=> unreachable
!(),
82 #[derive(PartialEq, Eq)]
83 enum C { D = 3, E = 4 }
86 assert_eq
!(match C
::D { F => 1, _ => 2, }
, 1);
89 #[derive(PartialEq, Eq)]
90 enum G { H = 3, I = 5 }
93 assert_eq
!(match G
::I { K => 1, _ => 2, }
, 1);
97 #[derive(PartialEq, Eq)]
99 const B
: A
= A
::AA(());
108 #[derive(PartialEq, Eq)]
113 const FOO
: Flags
= Flags { bits: 0x01 }
;
114 const BAR
: Flags
= Flags { bits: 0x02 }
;
115 match (Flags { bits: 0x02 }
) {
116 FOO
=> unreachable
!(),
123 assert_eq
!(match (true, false) {
130 assert_eq
!(match Some(Some(Direction
::North
)) {
132 Some(Some(Direction
::North
)) => 2,
133 Some(Some(EAST
)) => 3,
134 Some(Some(Direction
::South
)) => 4,
135 Some(Some(Direction
::West
)) => 5,
139 assert_eq
!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }
) {
140 Foo { bar: None, baz: NewBool(true) }
=> 1,
141 Foo { bar: NONE, baz: NEW_FALSE }
=> 2,
143 Foo { bar: _, baz: NEW_FALSE }
=> 4,
144 Foo { bar: Some(Direction::West), baz: NewBool(true) }
=> 5,
145 Foo { bar: Some(Direction::South), baz: NewBool(true) }
=> 6,
146 Foo { bar: Some(EAST), .. }
=> 7,
147 Foo { bar: Some(Direction::North), baz: NewBool(true) }
=> 8
150 assert_eq
!(match (EnumWithStructVariants
::Variant2 { dir: Direction::North }
) {
151 EnumWithStructVariants
::Variant1(true) => 1,
152 EnumWithStructVariants
::Variant1(false) => 2,
153 EnumWithStructVariants
::Variant2 { dir: Direction::West }
=> 3,
155 EnumWithStructVariants
::Variant2 { dir: Direction::South }
=> 5,
156 EnumWithStructVariants
::Variant2 { dir: Direction::East }
=> 6