Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {}
- fn test(condition: bool) -> u32 {
- let mut first = 33;
- let mut second = 99;
- // Only this can be modified
- // -------------------v
- if condition {
- let tmp = first;
- first = second;
- second = tmp;
- }
- // -------------------^
- // This would be an alternative, but the 'else' branch seems pointless
- let (first, second) = if condition {
- (second, first)
- } else {
- (first, second)
- };
- // This does not work
- //if condition {
- // (first, second) = (second, first);
- //}
- first + second
- }
Add Comment
Please, Sign In to add comment