的使用以下功能:锈使用移动值
fn factors(number: &BigInt) -> Vec<BigInt> {
let mut n = number.clone();
let mut i: BigInt = ToBigInt::to_bigint(&2).unwrap();
let mut factors = Vec::<BigInt>::new();
while i * i <= n {
if (n % i) == ToBigInt::to_bigint(&1).unwrap() {
i = i + ToBigInt::to_bigint(&1).unwrap();
}
else {
n = n/i as BigInt;
factors.push(i);
}
i = i + ToBigInt::to_bigint(&1).unwrap();
}
if n > i {
factors.push(n);
}
factors
}
我得到移动值误差字面上每次为i
或n
时,从开头的行while
,也在if
。我读过关于借款的文章,我理解得体,但这个东西我不明白。 我根本不是“复制”这个值,所以我没有看到任何地方我可能会失去变量的所有权。
BigInt是什么类型?它来自哪个箱子? –
ow,对不起,它来自'num'。这是一个很大的int,它没有实现'Copy'特性,因为这会非常非常非常耗费CPU时间。 (我知道我也在这里复制,我无法找到更好的解决方案) – Epse
啊不需要道歉,只是想知道他们是哪种类型。 –