1#[macro_export]
2macro_rules! if_else {
3 ($c:expr, $t:expr, $f:expr) => {
4 if $c {
5 $t
6 } else {
7 $f
8 }
9 };
10}
11
12#[macro_export]
13macro_rules! ternary {
14 ($c:expr, $t:expr, $f:expr) => {
15 if_else!($c, $t, $f)
16 };
17}
18
19#[cfg(test)]
20mod tests {
21 #[test]
22 fn ifelse_works() {
23 assert_eq!(7, if_else!(true, 7, 11));
24 assert_eq!(11, if_else!(false, 7, 11));
25
26 assert_eq!(11, if_else!(false, 7, 11));
27 assert_ne!(7, if_else!(false, 7, 11));
28 }
29
30 #[test]
31 fn ternary_works() {
32 assert_eq!(7, ternary!(true, 7, 11));
33 assert_eq!(11, ternary!(false, 7, 11));
34
35 assert_eq!(11, ternary!(false, 7, 11));
36 assert_ne!(7, ternary!(false, 7, 11));
37 }
38}