DEV Community

Discussion on: How can you swap two variables without using a third?

Collapse
 
qm3ster profile image
Mihail Malo
use std::mem;

let mut x = 5;
let mut y = 42;

mem::swap(&mut x, &mut y);

assert_eq!(42, x);
assert_eq!(5, y);