Crates.io | swap-n |
lib.rs | swap-n |
version | 0.1.1 |
source | src |
created_at | 2022-01-22 02:57:58.850653 |
updated_at | 2022-01-22 02:58:47.429663 |
description | an n argument extension to std::mem::swap |
homepage | |
repository | https://github.com/swooping-magpie/swap-n |
max_upload_size | |
id | 518862 |
size | 4,275 |
Very simply "n" argument extension to core::mem::swap.
Wrote it for doing a linked-list question on leetcode
Add the following to your Cargo.toml
swap-n = "0.1"
Use either #[macro_use] extern crate swap_n;
or for newer versions, directly call swap_n::swap_n
or via use swap_n::swap_n;
use swap_n::swap_n;
fn main() {
let mut x = std::boxed::Box::new(1);
let mut y = std::boxed::Box::new(2);
let mut z = std::boxed::Box::new(3);
let mut w = std::boxed::Box::new(4);
println!("The old values of x, y, z, w: {} {} {} {}", *x, *y, *z, *w);
swap_n!(&mut x, &mut y, &mut z, &mut w);
println!("The new values of x, y, z, w: {} {} {} {}", *x, *y, *z, *w);
}
MIT license