//! Binary / byte maniuplation use bytes::BufMut; /// Concatenate an iterator of byte slices into a buffer. /// /// # Returns /// The number of bytes written /// # Panics /// If the buffer cannot hold all the slices pub fn collect_slices_into(into: &mut B, from: I) -> usize where I: IntoIterator, T: AsRef<[u8]> { let mut done =0; for slice in from.into_iter() { let s = slice.as_ref(); into.put_slice(s); done+=s.len(); } done } /// Collect an iterator of byte slices into a new exact-size buffer. /// /// # Returns /// The number of bytes written, and the new array /// /// # Panics /// If the total bytes in all slices exceeds `SIZE`. pub fn collect_slices_exact(from: I) -> (usize, [u8; SIZE]) where I: IntoIterator, T: AsRef<[u8]> { let mut output = [0u8; SIZE]; (collect_slices_into(&mut &mut output[..], from), output) }