From ef8b80bfa889943fb221316899714bbfaf16a0d8 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 7 Oct 2020 00:04:24 -0600 Subject: [PATCH] helper function vec_to_array --- src/util.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util.rs b/src/util.rs index 865416b..22cead1 100644 --- a/src/util.rs +++ b/src/util.rs @@ -43,6 +43,13 @@ macro_rules! utf8_to_utf16_array { } } +pub fn vec_to_array(vec: Vec) -> [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 {