1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! This crate provides a [`fallthrough`] macro,
//! which allows performing a pattern match with fallthrough through the arms,
//! in the style of [C `switch`](https://en.cppreference.com/w/c/language/switch).
/// Accepts a match scrutinee,
/// followed by a comma-separated list of zero or more pattern match arms.
/// All arms but the first must be preceded with a `'label: `. Only the first arm
/// can access identifiers bound by the pattern match. Inside the match arms,
/// calling `break 'label;` will jump to the label's corresponding match arm
/// (you can only jump downwards). The list of arms can optionally be followed by a final
/// trailing label, which can be used to jump out of the fallthrough entirely.
///
/// # Example
///
/// ```
/// use fallthrough::fallthrough;
///
/// fn fall(scrutinee: u32) -> u32 {
/// let mut ret: u32 = 0;
///
/// fallthrough!(scrutinee,
/// val @ (0 | 63..) => ret = val + 7,
/// 'one: 1 => ret += 8,
/// 'two: 2 => ret += 9,
/// 'three: 3 if true => { ret += 10; break 'end },
/// 'four: 4 => ret = 42,
/// 'five: 5 => { ret += 1; break 'seven },
/// 'six: 6 => ret = 3,
/// 'seven: _ => ret *= 2,
/// 'end
/// );
/// ret
/// }
///
/// fn main() {
/// assert_eq!(fall(0), 34);
/// assert_eq!(fall(1), 27);
/// assert_eq!(fall(2), 19);
/// assert_eq!(fall(3), 10);
/// assert_eq!(fall(4), 86);
/// assert_eq!(fall(5), 2);
/// assert_eq!(fall(6), 6);
/// assert_eq!(fall(7), 0);
/// assert_eq!(fall(64), 98);
/// }
/// ```
), $,* }
};
}
;
=> ;
=> ;
}