pub trait BytesTransferExt: Sized { // Turn u32 into u8 fn bytes_transfer(self) -> BytesTransfer where Self: Iterator; } impl> BytesTransferExt for I { // Turn u32 into u8 fn bytes_transfer(self) -> BytesTransfer { BytesTransfer { iter: self, shift: 32, word: 0, } } } pub struct BytesTransfer + Sized> { iter: I, shift: u8, word: u32, } impl + Sized> Iterator for BytesTransfer { type Item = u8; fn next(&mut self) -> Option { if self.shift < 24 { self.shift += 8; Some((self.word >> self.shift) as u8) } else { self.shift = 0; self.iter.next() .map(|word| { self.word = word; word as u8 }) } } }