[][src]Macro conditional::conditional

macro_rules! conditional {
    #[proc_macro_hack] => { ... };
}

Lets you use the syntax of the conditional operator in Rust. Also known as the ternary operator.

Examples

let x = conditional!(69 > 42 ? "hello" : "world");
assert_eq!(x, "hello");
let r: Result<i32, String> = Ok(5);
// More complicated expressions are supported, but you might have to use
// parentheses to satisfy the macro parser
let x = conditional!((r? > 42) ? "hello" : "world");
assert_eq!(x, "world");
// More complicated expressions are supported, but you might have to use
// parentheses to satisfy the macro parser
let x = conditional!(("3".parse::<i32>().map_err(|e| e.to_string())? > 42)
    ? "hello" : "world");
assert_eq!(x, "world");