diff --git a/src/cidr/direct.rs b/src/cidr/direct.rs index e517a72..a6232b1 100644 --- a/src/cidr/direct.rs +++ b/src/cidr/direct.rs @@ -309,7 +309,7 @@ mod tests { Ipv4Addr::new(1, 2, 3, 2), Ipv4Addr::new(1, 2, 3, 3), ], - (&cidr).into_iter().addresses().collect::>() + cidr.into_iter().addresses().collect::>() ); } diff --git a/src/parsers/inetaddr.rs b/src/parsers/inetaddr.rs index acee9fe..6bfe919 100644 --- a/src/parsers/inetaddr.rs +++ b/src/parsers/inetaddr.rs @@ -44,13 +44,13 @@ pub fn inet_addr(s: &str) -> Option { slots[0] } else { let mut base: u32 = 0; - for ndx in 0..last_slot { - if slots[ndx] >= 256 { + for (ndx, &slot) in slots.iter().enumerate().take(last_slot) { + if slot >= 256 { // leading parts must be octects return None; } // shift by 24, 16 or 8 - base = base | (slots[ndx] << (3 - ndx) * 8); + base |= slots[ndx] << ((3 - ndx) * 8); } // last 3 => have 4 => 1 byte, last 2 => have 3 => 2 bytes, last 1 => have 2 => 3 bytes let last_slot_bit_limit = (4 - last_slot) * 8;