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
80
//! A macro for matching on boolean conditions.
//!
//! For the full documentation, see [`cond`].
/// A macro for matching on boolean conditions, like an empty [Go `switch` statement].
///
/// If the branches evalutate to `()`, you don't need a default branch.
///
/// ```
/// # use cond::cond;
/// let a = 4;
/// let b = 5;
/// cond! {
/// a < b => println!("a is less than b"),
/// a > b => println!("a is greater than b"),
/// }
/// ```
///
/// If the branches evalute to any type other than `()`, you must include a default branch. The
/// default branch uses `_` instead of a condition and must come last.
///
/// ```
/// # use cond::cond;
/// let a = 4;
/// let b = 5;
/// let text = cond! {
/// a < b => "a is less than b",
/// a > b => "a is greater than b",
/// _ => "a is equal to b",
/// };
/// assert_eq!(text, "a is less than b");
/// ```
///
/// # Caveat
///
/// Expressions that end with blocks must still have commas after them in `cond` invocations, unlike
/// in `match` blocks.
///
/// The following `match` block does not need commas after each of its arms:
///
/// ```
/// let x = 5;
/// match x {
/// ..=4 => {
/// println!("x is 4 or less");
/// }
/// // No comma needed!
/// 5.. => {
/// println!("x is 5 or greater");
/// }
/// }
/// ```
///
/// But the equivalent `cond` invocation fails to compile:
///
/// ```compile_fail
/// # use cond::cond;
/// let x = 5;
/// cond! {
/// x <= 4 => {
/// println!("x is 4 or less");
/// }
/// // Comma needed here!
/// x >= 5 => {
/// println!("x is 5 or greater");
/// }
/// }
/// ```
///
/// [Go `switch` statement]: <https://go.dev/ref/spec#Switch_statements>