[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 446 Bytes

README.md

File metadata and controls

20 lines (16 loc) · 446 Bytes

Ternary Operator

Rust doesn't support return (condition) ? if_true : if_false;. This crate exports a macro that implements this feature.

fn is_ipv4(val: &str) -> i32 {
    ternary!(val == "ipv4", 4, 16)
}

If you just want to copy the small macro, here you go 😅

#[macro_export]
macro_rules! ternary {
    ($condition: expr, $_true: expr, $_false: expr) => {
        if $condition { $_true } else { $_false }
    };
}