pub fn swap(x: &mut T, y: &mut T)
Swaps the values at two mutable locations, without deinitializing either one.
举例:
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);
/// Insert a term into a linear constraint.
fn insert_coefficient(
&mut self,
var: Variable,
coeff: Coeff,
y: &Self::LinearConstraintIndex,
) {
use std::mem;
let index = *y - 1;
let mut lc = LinearCombination::zero();
mem::swap(&mut lc, &mut self.lc[index].0);
lc = lc + (coeff, var);
mem::swap(&mut lc, &mut self.lc[index].0);
}
参考资料: [1] https://doc.rust-lang.org/std/mem/fn.swap.html