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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// devela::code::util::is
//
//! inline if macro.
//
/// Conditional evaluation.
///
/// Combines:
/// 1. `if`/`else` conditions
/// 2. `if let` pattern matching
/// 3. Temporary value binding
///
/// # Examples
///
/// 1. Replacing `if`:
/// ```
/// # use devela::is;
/// is![true; print!("true")];
///
/// // This
/// let s = is![1 > 0; true; false];
///
/// // Would be equivalent to
/// let s = if 1 > 0 {
/// true
/// } else {
/// false
/// };
/// ```
///
/// 2. Replacing `if let`:
/// ```
/// # use devela::is;
/// let num = Some(123);
///
/// // This
/// is![let Some(n) = num ; println!("num:{n}") ; { dbg![num]; }];
///
/// // Would be equivalent to
/// if let Some(n) = num {
/// println!("num:{n}")
/// } else {
/// dbg![num];
/// }
/// ```
///
/// Nested:
/// ```
/// # use devela::is;
/// let mut s = String::new();
/// let is_premium = Some(true);
///
/// // This
/// is![let Some(b) = is_premium; is![b; s += " [premium]"]];
///
/// // Would be equivalent to
/// if let Some(b) = is_premium {
/// if b {
/// s += " [premium]";
/// }
/// }
/// ```
///
/// 3. Temporary value binding:
/// ```
/// # use devela::{format_args, is, FmtWrite};
/// let mut s = String::new();
/// let (a, b) = (1, 2);
///
/// // This
/// is![
/// tmp A = format_args!("A{a}");
/// tmp B = format_args!("B{b}");
/// write!(s, "{A}+{B},");
/// ];
/// assert_eq![&s, "A1+B2,"];
///
/// // Would be equivalent to
/// match format_args!("A{a}") {
/// A => match format_args!("B{b}") {
/// B => { write!(s, "{A}+{B},"); }
/// }
/// }
/// ```
///
/// Otherwise it fails with `E0716: temporary value dropped while borrowed`.
/// ```compile_fail,E0716
/// # use devela::{format_args, FmtWrite};
/// let mut s = String::new();
/// let (a, b) = (1, 2);
///
/// let A = format_args!("A{a}"); // ← freed here
/// let B = format_args!("B{b}"); // ← freed here
/// write!(s, "{A}+{B},");
/// ```
pub use is;
/// Renamed to [`is`].
pub use iif;