generic_array_storage/
conv.rs1use generic_array::{ArrayLength, IntoArrayLength};
2use nalgebra::{Const, DimName, DimNameAdd, DimNameMul, DimNameProd, DimNameSum, U0, U1, U2};
3use typenum::{B0, B1, UInt, UTerm};
4
5pub trait Conv {
16 type TNum: ArrayLength;
18
19 type Nalg: DimName;
21
22 fn new_nalg() -> Self::Nalg {
24 Self::Nalg::name()
25 }
26}
27
28impl Conv for UTerm {
29 type Nalg = U0;
30
31 type TNum = Self;
32}
33
34impl<U: Conv> Conv for UInt<U, B1>
35where
36 U: ArrayLength,
37 UInt<U, B0>: Conv,
38 <UInt<U, B0> as Conv>::Nalg: DimNameAdd<U1>,
39{
40 type TNum = Self;
41
42 type Nalg = DimNameSum<<UInt<U, B0> as Conv>::Nalg, U1>;
43}
44
45impl<U: Conv> Conv for UInt<U, B0>
46where
47 U: ArrayLength,
48 U::Nalg: DimNameMul<U2>,
49{
50 type TNum = Self;
51
52 type Nalg = DimNameProd<U::Nalg, U2>;
53}
54type TNum<const N: usize> = typenum::Const<N>;
55
56impl<const N: usize> Conv for TNum<N>
57where
58 Self: IntoArrayLength,
59{
60 type TNum = <Self as IntoArrayLength>::ArrayLength;
61
62 type Nalg = Const<N>;
63}
64
65impl<const N: usize> Conv for Const<N>
66where
67 TNum<N>: IntoArrayLength,
68{
69 type TNum = <TNum<N> as IntoArrayLength>::ArrayLength;
70
71 type Nalg = Self;
72}