问题描述
在行:
let mut bins: Vec<u32> = vec![0; 1000];
let total = bins.iter().sum();
错误:
error[E0282]: type annotations needed
--> src/lib.rs:191:7
|
191 | let total = bins.iter().sum();
| ^^^^^ consider giving `total` a type
我可与修复:
let total: u32 = bins.iter().sum();
或:
let total = bins.iter().sum::<u32>();
类型 u32
出现在 Vec 的声明中。为什么 rustc 不能推断 sum 的类型与元素的类型相同?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)