[−][src]Macro compile_ops::ternary
ternary!() { /* proc-macro */ }
Ternary operations with $bool:expr ? $code:expr $(! else_code)?
syntax for shorter and more legible conditionals.
This macro expand to if bool_expr { code } else { else_code }
so does not prevent you for declaring
new scopes,take it count in position-sensitive code,because inner blocks can access outer ones this is not
typically a problem for safe code.
Because procedural macros does not expand if them are inside the arguments of another,you can't nest
ternary as you can do with normal if
statements.
Examples
#![feature(proc_macro_hygiene)] // needed here due to the use in let // statements but generally unneccesary use compile_ops::ternary; let mut one = 1; let mut two = ternary!(one == 1 ? 2 ! 3); assert_eq!(two, 2); one = 2; two = ternary!(one == 1 ? 2 ! 3); ternary!(two == 3 ? one = 1); assert_eq!(two, 3); assert_eq!(one, 1);