Guest User

Untitled

a guest
Jul 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. fn main() {}
  2. fn test(condition: bool) -> u32 {
  3. let mut first = 33;
  4. let mut second = 99;
  5.  
  6. // Only this can be modified
  7. // -------------------v
  8. if condition {
  9. let tmp = first;
  10. first = second;
  11. second = tmp;
  12. }
  13. // -------------------^
  14.  
  15. // This would be an alternative, but the 'else' branch seems pointless
  16. let (first, second) = if condition {
  17. (second, first)
  18. } else {
  19. (first, second)
  20. };
  21.  
  22. // This does not work
  23. //if condition {
  24. // (first, second) = (second, first);
  25. //}
  26.  
  27. first + second
  28. }
Add Comment
Please, Sign In to add comment