3 ms·
Sure, although that's not a ternary operator, it's just an if expression. In practice you tend to see such casts in code where we directly needed the integer.
by tialaramex 4y ago
Sure, although that's not a ternary operator, it's just an if expression.
In practice you tend to see such casts in code where we directly needed the integer. I think Clippy (Rust's linter) proposes them where you've written if some_bool { 1 } else { 0 } because well, that's what the as cast does anyway.
- alpaca128 4y agoI find the if expression easier to read to be honest. With the integer cast example you need to mentally translate the booleans and do a subtraction in your head to figure out what integer values are involved, with the if expression it's directly visible.