Maybe this is trivial, but right now I would not know how to do this:
#[derive(Debug)]
struct Point2f {
x: f32,
y: f32,
}
fn some_fn(to_swap: &mut [f32]) {
to_swap.swap(0_usize, 3_usize);
}
fn main() {
let mut swap_me: Vec<Point2f> = Vec::new();
swap_me.push(Point2f { x: 0.0, y: 1.0 });
swap_me.push(Point2f { x: 2.0, y: 3.0 });
println!("replace");
println!("{:?}", swap_me[0]);
println!("{:?}", swap_me[1]);
// some_fn(&mut swap_me[..]);
let tmp = swap_me[0].x;
swap_me[0].x = swap_me[1].y;
swap_me[1].y = tmp;
// replace three lines above through function call
assert!(swap_me[0].x == 3.0);
assert!(swap_me[1].y == 0.0);
println!("by");
println!("{:?}", swap_me[0]);
println!("{:?}", swap_me[1]);
}
Can this be done via From
and Into
?