Rust implementation of swap.