helper function vec_to_array

This commit is contained in:
jake 2020-10-07 00:04:24 -06:00
parent 6b1dfa4feb
commit ef8b80bfa8

View File

@ -43,6 +43,13 @@ macro_rules! utf8_to_utf16_array {
}
}
pub fn vec_to_array<T: Default + Copy, const N: usize>(vec: Vec<T>) -> [T; N] {
let mut result: [T; N] = [T::default(); N];
for (i, v) in vec.into_iter().enumerate() {
result[i] = v
}
result
}
#[cfg(test)]
mod test {