您当前的位置: 首页 >  rust

mutourend

暂无认证

  • 2浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

rust std::mem::swap

mutourend 发布时间:2019-10-11 16:29:42 ,浏览量:2

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

关注
打赏
1664532908
查看更多评论
立即登录/注册

微信扫码登录

0.0991s