我有以下情况:
use num_bigint::BigUint;
fn add_one(px: BigUint, py: BigUint) -> (BigUint, BigUint) {
(px+1u32, py+1u32)
}
fn test(x: &[u8], y: &[u8]) {
let mut x = BigUint::from_bytes_le(x);
let mut y = BigUint::from_bytes_le(y);
(x,y) = add_one(x, y);
}
当我尝试编译时,出现以下编译错误:
error[E0658]: destructuring assignments are unstable
--> src/lib.rs:76:11
|
76 | (x,y) = ecc_add(x, y);
| ----- ^
| |
| cannot assign to this expression
|
= note: see issue #71126 <https://github.com/rust-lang/rust/issues/71126> for more information
这是什么意思?
let (x,y) = add_one(x, y);
似乎解决了错误,但我认为这不会改变原始的 x
和 y
变量(?),而且我想避免创建任何临时变量。当我使用 (x, y) = (x+1u32, y+1u32);
时,我得到相同的错误。如果我改用单个返回值,则可以正常工作:
use num_bigint::BigUint;
fn add_one(px: BigUint) -> BigUint {
px+1u32
}
fn test(x: &[u8]) {
let mut x = BigUint::from_bytes_le(x);
x = add_one(x)
}
我该如何将
x
和y
赋值为add_one
的返回值?