1 //! This library provides array utils.
2 
3 /// Converts a vector of bytes to a fixed sized array.
4 /// If the vector is longer it will be truncated and if shorter
5 /// zero padding will be added at the end.
to_sized_array<const S: usize>(v: &Vec<u8>) -> [u8; S]6 pub fn to_sized_array<const S: usize>(v: &Vec<u8>) -> [u8; S] {
7     // Okay to do naked unwrap since we enforce at compile time that
8     // the iter length is the same as the destination array length.
9     v.iter().chain(std::iter::repeat(&0)).take(S).cloned().collect::<Vec<u8>>().try_into().unwrap()
10 }
11