ternary_operator_macro/
lib.rs

1#[macro_export]
2macro_rules! ternary {
3    ($condition: expr => $true_expr: expr , $false_expr: expr) => {
4        if $condition {
5            $true_expr
6        } else {
7            $false_expr
8        }
9    };
10}
11
12#[cfg(test)]
13mod tests {
14
15    use super::*;
16
17    #[test]
18    fn test_ternary() {
19        assert_eq!(ternary!(true => "a","b"),"a");
20        assert_eq!(ternary!(false => "a","b"),"b");
21    }
22}