clippy: fix/allow needless_range_loop

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-01-19 15:03:04 +01:00
parent 0d2133db98
commit 382f10a0cc
3 changed files with 7 additions and 9 deletions

View File

@ -51,6 +51,7 @@ pub static IPV4_REVERSE_MASK: &[&str] = &[
lazy_static! {
pub static ref IPV4_MASK_HASH_LOCALNET: HashMap<&'static str, u8> = {
let mut map = HashMap::new();
#[allow(clippy::needless_range_loop)]
for i in 8..32 {
map.insert(IPV4_REVERSE_MASK[i], i as u8);
}

View File

@ -57,9 +57,9 @@ impl ApiConfig {
prefix.push_str(components[0]);
if let Some(subdir) = self.aliases.get(&prefix) {
filename.push(subdir);
for i in 1..comp_len { filename.push(components[i]) }
components.iter().skip(1).for_each(|comp| filename.push(comp));
} else {
for i in 0..comp_len { filename.push(components[i]) }
components.iter().for_each(|comp| filename.push(comp));
}
}
filename

View File

@ -95,19 +95,16 @@ fn decode_volume_statistics(data: &[u8]) -> Result<Lp17VolumeStatistics, Error>
let read_be_counter = |reader: &mut &[u8], len: u8| {
let len = len as usize;
if len == 0 || len > 8 {
bail!("invalid conter size '{}'", len);
}
let mut buffer = [0u8; 8];
reader.read_exact(&mut buffer[..len])?;
let mut value: u64 = 0;
for i in 0..len {
value <<= 8;
value |= buffer[i] as u64;
}
let value = buffer
.iter()
.take(len)
.fold(0, |value, curr| (value << 8) | *curr as u64);
Ok(value)
};