4 ms·
If you insist on the assignments: x = something ? ((a=foo()), baz(a)) : ((b = bar()), baz(b)); Otherwise: x = something ? baz(foo()) : baz(bar());
by tacostakohashi 10y ago
If you insist on the assignments:
x = something ? ((a=foo()), baz(a)) : ((b = bar()), baz(b));
Otherwise:
x = something ? baz(foo()) : baz(bar());
- vertex-four 10y agoa and b have to be defined before the statement containing the terniary expression here. And the point is that you can embed arbitrary multi-statement logic in your if expressions in Rust in the same way you'd do it anywhere else.