Я пытаюсь использовать следующий код:Перемещено значение при умножении числа
fn get_max(string:Vec<BigUint>) -> BigUint {
let mut max:BigUint = num::zero();
for i in 0..(string.len()-13) {
let mut prod:BigUint = num::one();
for j in i..(i+13) {
prod.mul(&string[j]);
}
if prod.clone().gt(&max) {
max = prod;
}
}
max
}
Но я получаю следующее сообщение об ошибке при попытке компиляции:
src/main.rs:13:4: 13:8 error: use of moved value: `prod`
src/main.rs:13 prod.mul(&string[j]);
^~~~
note: `prod` was previously moved here because it has type `num::bigint::BigUint`, which is non-copyable
src/main.rs:16:6: 16:10 error: use of moved value: `prod`
src/main.rs:16 if prod.clone().gt(&max) {
^~~~
src/main.rs:13:4: 13:8 note: `prod` moved here because it has type `num::bigint::BigUint`, which is non-copyable
src/main.rs:13 prod.mul(&string[j]);
^~~~
src/main.rs:17:10: 17:14 error: use of moved value: `prod`
src/main.rs:17 max = prod;
^~~~
src/main.rs:13:4: 13:8 note: `prod` moved here because it has type `num::bigint::BigUint`, which is non-copyable
src/main.rs:13 prod.mul(&string[j]);
^~~~
error: aborting due to 3 previous errors
Насколько я могу сказать , Я никогда не двигаюсь prod
, так что не так?
Спасибо! Я попробовал * = сначала, но не понял, что работает только *. Приятно знать, что! – Tyler
Последнее обсуждение работы '* =' работает в основном на https://github.com/rust-lang/rfcs/pull/953 –