【发布时间】:2019-01-04 08:56:29
【问题描述】:
如:
let mut a : usize = 0xFF;
a += -1; // -1 may be from other variable, so there can't be a -= 1;
println!("{}", a);
输出是:
error[E0277]: the trait bound `usize: std::ops::Neg` is not satisfied
不管怎样?
【问题讨论】:
-
很遗憾,错误信息对您没有多大帮助。
-
您是坚持使用
usize,还是可以改用isize?或者更好的是,像i64这样的已知位宽类型? -
@MatthieuM。实际上是数组的索引,只能是$usize$
标签: rust integer integer-overflow unsigned-integer