rust - 从元组赋值循环中隐藏变量
问题描述
我有以下内容:
use num_bigint::BigUint;
fn add_one(px: &BigUint, py: &BigUint) -> (BigUint, BigUint) {
(px+1u32, py+1u32)
}
fn test(x: &[u8], y: &[u8]) {
let x = BigUint::from_bytes_le(x);
let y = BigUint::from_bytes_le(y);
for _ in 1..5 {
let (x,y) = add_one(&x, &y);
}
}
我收到警告:
warning: unused variable: `x`
--> src/lib.rs:109:14
|
109 | let (x,y) = ecc_add(&x, &y, &x, &y);
| ^ help: if this is intentional, prefix it with an underscore: `_x`
这不是故意的,因为我想在每次迭代中修改x
和。y
如何在 for 循环中隐藏变量?
解决方案
按照 Denys Séguret 给出的建议,我现在有以下解决方案:
struct Point {
x: BigUint,
y: BigUint
}
fn add_one(p: Point) -> Point {
Point {x: p.x + 1u32, y: p.y + 1u32}
}
fn test(x: &[u8], y: &[u8]) {
let x = BigUint::from_bytes_le(x);
let y = BigUint::from_bytes_le(y);
let mut point = Point {x: x, y: y};
for _ in 1..5 {
point = add_one(point);
}
}
推荐阅读
- c++ - 两个模板模板参数,一个需要另一个
- c - 通过在 C 中的引用传递来修改函数内部的字符串
- ios - 为什么 Xcode 13 不惜一切代价忽略设备方向设置?
- bootstrap-5 - 如何重置bootstrap 5 text-muted的效果
- powershell - 如何在 Powershell 中实现二进制哈希字符串的 Base64 URL 安全编码?
- r - 如何在 R 中按日期合并/堆叠观察结果
- react-native - 我如何使用反应原生日期时间选择器
- python - kivy 中的大量小部件 - 优化
- javascript - 模块解析失败:意外的令牌 (32:14) 在导入 api 库时使用这些加载程序处理了文件
- php - 我可以使用我的 php 应用程序在 Google 日历中添加事件吗?