当运行cargo clippy时,它会抱怨代码如下:
pub fn from_bytes(data: [u8; 72]) -> Stuff {
let mut ts = [0u8; 8];
let mut cs = [0u8; 64];
for b in 0..8 {
ts[b] = data[b];
}
for bb in 0..64 {
cs[bb] = data[bb + 8];
}
}使用
warning: the loop variable `bb` is used to index `cs`
--> src/main.rs:9:5
|
9 | / for bb in 0..64 {
10 | | cs[bb] = data[bb + 8];
11 | | }
| |_____^
|
= note: #[warn(needless_range_loop)] on by default
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_range_loop
help: consider using an iterator
| for (bb, <item>) in cs.iter().enumerate().take(64) {我不能理解这个information。如何更改为建议的方法?我不明白像这样的东西
for (bb, <item>) in cs.iter().enumerate().take(64)可以应用到我的用例中。
发布于 2017-06-15 18:17:50
ts.clone_from_slice(&data[..8]);
cs.clone_from_slice(&data[8..]);https://stackoverflow.com/questions/44564772
复制相似问题