mutable iterator in encode_length

This commit is contained in:
Grant Wuerker 2018-10-24 07:56:58 -05:00
parent 4c272d7f0a
commit 625fc4c9b9

View File

@ -1,5 +1,3 @@
#![allow(unknown_lints)]
use super::{ use super::{
LENGTH_BYTES LENGTH_BYTES
}; };
@ -80,10 +78,9 @@ pub fn encode_length(len: usize, length_bytes: usize) -> Vec<u8> {
assert!(length_bytes > 0); // For sanity assert!(length_bytes > 0); // For sanity
assert!((len as usize) < 2usize.pow(length_bytes as u32 * 8)); assert!((len as usize) < 2usize.pow(length_bytes as u32 * 8));
let mut header: Vec<u8> = vec![0; length_bytes]; let mut header: Vec<u8> = vec![0; length_bytes];
#[allow(needless_range_loop)] for (i, header_byte) in header.iter_mut().enumerate() {
for i in 0..length_bytes {
let offset = (length_bytes - i - 1) * 8; let offset = (length_bytes - i - 1) * 8;
header[i] = ((len >> offset) & 0xff) as u8; *header_byte = ((len >> offset) & 0xff) as u8;
}; };
header header
} }