use crate::HList;
pub trait FromHList {
type HList: HList;
fn from_hlist(hlist: Self::HList) -> Self;
}
impl<T> FromHList for T
where
T: HList,
{
type HList = T;
fn from_hlist(hlist: Self::HList) -> Self {
hlist
}
}
macro_rules! hlist_from_tuple {
($($types:ident),*) => {
impl<$($types),*> From<($($types,)*)> for $crate::HList!($($types,)*) {
#[allow(non_snake_case)]
fn from(value: ($($types,)*)) -> Self {
let ($($types,)*) = value;
$crate::hlist!($($types,)*)
}
}
impl<$($types),*> FromHList for ($($types,)*) {
type HList = $crate::HList!($($types,)*);
fn from_hlist(hlist: Self::HList) -> Self {
Self::from(hlist)
}
}
};
}
hlist_from_tuple!(A, B, C, D, E, F, G, H, I, J, K, L);
hlist_from_tuple!(A, B, C, D, E, F, G, H, I, J, K);
hlist_from_tuple!(A, B, C, D, E, F, G, H, I, J);
hlist_from_tuple!(A, B, C, D, E, F, G, H, I);
hlist_from_tuple!(A, B, C, D, E, F, G, H);
hlist_from_tuple!(A, B, C, D, E, F, G);
hlist_from_tuple!(A, B, C, D, E, F);
hlist_from_tuple!(A, B, C, D, E);
hlist_from_tuple!(A, B, C, D);
hlist_from_tuple!(A, B, C);
hlist_from_tuple!(A, B);
hlist_from_tuple!(A);
hlist_from_tuple!();
pub trait IntoHList {
type HList: HList;
fn into_hlist(self) -> Self::HList;
}
impl<T> IntoHList for T
where
T: HList,
{
type HList = T;
fn into_hlist(self) -> Self::HList {
self
}
}
macro_rules! tuple_from_hlist {
($($types:ident),*) => {
impl<$($types),*> From<$crate::HList!($($types,)*)> for ($($types,)*) {
#[allow(non_snake_case, clippy::unused_unit)]
fn from(value: $crate::HList!($($types,)*)) -> Self {
let $crate::hlist!($($types,)*) = value;
($($types,)*)
}
}
impl<$($types),*> IntoHList for ($($types,)*) {
type HList = $crate::HList!($($types,)*);
fn into_hlist(self) -> Self::HList {
self.into()
}
}
};
}
tuple_from_hlist!(A, B, C, D, E, F, G, H, I, J, K, L);
tuple_from_hlist!(A, B, C, D, E, F, G, H, I, J, K);
tuple_from_hlist!(A, B, C, D, E, F, G, H, I, J);
tuple_from_hlist!(A, B, C, D, E, F, G, H, I);
tuple_from_hlist!(A, B, C, D, E, F, G, H);
tuple_from_hlist!(A, B, C, D, E, F, G);
tuple_from_hlist!(A, B, C, D, E, F);
tuple_from_hlist!(A, B, C, D, E);
tuple_from_hlist!(A, B, C, D);
tuple_from_hlist!(A, B, C);
tuple_from_hlist!(A, B);
tuple_from_hlist!(A);
tuple_from_hlist!();