Skip to main content

libutils_array/
conversions.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> SUPER
6use super::Array;
7
8//> HEAD -> ALLOC
9use alloc::vec::Vec;
10
11
12//^
13//^ CONVERSIONS
14//^
15
16//> CONVERSIONS -> FROM FIXED TO VARIABLE
17impl<Type, const M: usize, const N: usize> From<[Type; N]> for Array<Type, M> where [(); M - N]: {
18    #[inline]
19    fn from(value: [Type; N]) -> Self {return Array::from_iter(value)}
20}
21
22//> CONVERSIONS -> TO VEC
23impl<Type, const N: usize> Into<Vec<Type>> for Array<Type, N> {
24    #[inline]
25    fn into(self) -> Vec<Type> {return Vec::from_iter(self.into_iter())}
26}
27
28//> CONVERSIONS -> FROM FUNCTION
29impl<Type, const N: usize, Generator: FnMut(usize) -> Type> From<Generator> for Array<Type, N> {
30    #[inline]
31    fn from(mut value: Generator) -> Self {
32        let mut array = Self::new();
33        for index in 0..N {
34            array.push(value(index));
35        };
36        return array;
37    }
38}