Function std::mem::swap [] [src]

pub fn swap<T>(x: &mut T, y: &mut T)

Swap the values at two mutable locations of the same type, without deinitializing or copying either one.

Examples

fn main() { use std::mem; let x = &mut 5; let y = &mut 42; mem::swap(x, y); assert_eq!(42, *x); assert_eq!(5, *y); }
use std::mem;

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

mem::swap(x, y);

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