use crate::{Generic, One, Product, Sum, Zero};
pub fn singleton<T, U: Generic<Repr = Sum<Product<T, One>, Zero>>>(x: T) -> U {
U::from_repr(Sum::This(Product(x, One)))
}
pub fn cast<T: Generic, U: Generic<Repr = T::Repr>>(x: T) -> U {
U::from_repr(x.into_repr())
}
trait VariantCount {
const COUNT: u32;
}
impl VariantCount for Zero {
const COUNT: u32 = 0;
}
impl<T, R: VariantCount> VariantCount for Sum<T, R> {
const COUNT: u32 = 1 + R::COUNT;
}
#[allow(private_bounds)]
pub const fn variant_count<T>() -> u32
where
T: Generic,
T::Repr: VariantCount,
{
T::Repr::COUNT
}