4 ms·
You can do something similiar in rust. 'if' is an expression, so it can appear on the right hand side of an assignment. let x = if number > 2 { "yes" } else
by okbake 10y ago
You can do something similiar in rust. 'if' is an expression, so it can appear on the right hand side of an assignment.
let x = if number > 2 { "yes" } else { "no" };
It's not quite the same, and I'm not sure what the failure case would be if the 'else' statement was ommitted, but it comes close.
After experimenting with Rust and Elixir I've really come to like the 'everything is an expression' approach. That and pattern matching can make some things really expressive.
- alfiedotwtf 10y agoAh yes... ternaries. Actually, it's two things I miss :)