Crates.io | terny |
lib.rs | terny |
version | 0.2.0 |
source | src |
created_at | 2023-04-28 20:58:43.706866 |
updated_at | 2023-04-29 07:43:42.626366 |
description | A simple, C-like, ternary operator for cleaner syntax. |
homepage | |
repository | https://github.com/KaitlynEthylia/terny |
max_upload_size | |
id | 851706 |
size | 5,763 |
A simple ternary operator macro in rust. the iff!
macro is the only item exported by this crate, it simply takes three expressions, seperated by ?
and :
, and expands them info an if else statement.
iff!( condition
? expressionA
: expressionB );
expands to:
if condition {
expressionA
} else {
expressionB
}
It can also be used in assignment:
let value = iff!(condition
? expressionA
: expressionB );
It can also be used inline:
let value = iff!(condition ? exressionA : expressionB);
It may also be nested, although the code starts to look less clean at this point
let value = iff!(conditionA ? iff!(conditionB ? expressionA : expressionB) : expressionC);
Currently using the ?
operator within iff
is not possible, as there is no way (that I know of) to check for whitespace. This should be changeable once Tracking issue 54725 becomes stable.