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 Self: ArrayLength,
37 U: ArrayLength,
38 UInt<U, B0>: Conv,
39 <UInt<U, B0> as Conv>::Nalg: DimNameAdd<U1>,
40{
41 type TNum = Self;
42
43 type Nalg = DimNameSum<<UInt<U, B0> as Conv>::Nalg, U1>;
44}
45
46impl<U: Conv> Conv for UInt<U, B0>
47where
48 Self: ArrayLength,
49 U: ArrayLength,
50 U::Nalg: DimNameMul<U2>,
51{
52 type TNum = Self;
53
54 type Nalg = DimNameProd<U::Nalg, U2>;
55}
56type TNum<const N: usize> = typenum::Const<N>;
57
58impl<const N: usize> Conv for TNum<N>
59where
60 Self: IntoArrayLength,
61{
62 type TNum = <Self as IntoArrayLength>::ArrayLength;
63
64 type Nalg = Const<N>;
65}
66
67impl<const N: usize> Conv for Const<N>
68where
69 TNum<N>: IntoArrayLength,
70{
71 type TNum = <TNum<N> as IntoArrayLength>::ArrayLength;
72
73 type Nalg = Self;
74}