gitbutler/gitbutler-changeset/fixture/code4.txt

13 lines
452 B
Plaintext
Raw Normal View History

2024-01-15 16:50:59 +03:00
fn chunk_bytes<'a, const N: usize>(bytes: &'a [u8]) -> impl Iterator<Item = BitArray<N>> + 'a {
bytes
.chunks(N)
.map(|chunk| {
// Create a new byte array of size N and copy the chunk into it,
// padding with zeros if the chunk is shorter than N.
let mut padded_chunk = [0; N];
padded_chunk[..chunk.len()].copy_from_slice(chunk);
BitArray::new(padded_chunk)
})
}