use crate::type_level::{
cmp::{Compare, TEqual, TGreater, TLess},
to_value_traits::ToUsize,
};
use std_::marker::PhantomData;
#[cfg(test)]
mod tests;
mod sealed {
pub trait Sealed {}
}
use self::sealed::Sealed;
pub trait IsUnsigned: Sealed {}
impl<T> Sealed for Unsigned<T> {}
impl<T> IsUnsigned for Unsigned<T> {}
pub trait IsBit: Sealed {
const VALUE: bool;
}
impl Sealed for Bit0 {}
impl Sealed for Bit1 {}
impl IsBit for Bit0 {
const VALUE: bool = false;
}
impl IsBit for Bit1 {
const VALUE: bool = true;
}
pub struct Unsigned<T>(PhantomData<T>);
pub struct Bit0;
pub struct Bit1;
pub type U0 = Unsigned<(Bit0, Bit0, Bit0, Bit0, Bit0, Bit0)>;
pub type U1 = Unsigned<(Bit0, Bit0, Bit0, Bit0, Bit0, Bit1)>;
pub type U2 = Unsigned<(Bit0, Bit0, Bit0, Bit0, Bit1, Bit0)>;
pub type U3 = Unsigned<(Bit0, Bit0, Bit0, Bit0, Bit1, Bit1)>;
pub type U4 = Unsigned<(Bit0, Bit0, Bit0, Bit1, Bit0, Bit0)>;
pub type U5 = Unsigned<(Bit0, Bit0, Bit0, Bit1, Bit0, Bit1)>;
pub type U6 = Unsigned<(Bit0, Bit0, Bit0, Bit1, Bit1, Bit0)>;
pub type U7 = Unsigned<(Bit0, Bit0, Bit0, Bit1, Bit1, Bit1)>;
pub type U8 = Unsigned<(Bit0, Bit0, Bit1, Bit0, Bit0, Bit0)>;
pub type U9 = Unsigned<(Bit0, Bit0, Bit1, Bit0, Bit0, Bit1)>;
pub type U10 = Unsigned<(Bit0, Bit0, Bit1, Bit0, Bit1, Bit0)>;
pub type U11 = Unsigned<(Bit0, Bit0, Bit1, Bit0, Bit1, Bit1)>;
pub type U12 = Unsigned<(Bit0, Bit0, Bit1, Bit1, Bit0, Bit0)>;
pub type U13 = Unsigned<(Bit0, Bit0, Bit1, Bit1, Bit0, Bit1)>;
pub type U14 = Unsigned<(Bit0, Bit0, Bit1, Bit1, Bit1, Bit0)>;
pub type U15 = Unsigned<(Bit0, Bit0, Bit1, Bit1, Bit1, Bit1)>;
pub type U16 = Unsigned<(Bit0, Bit1, Bit0, Bit0, Bit0, Bit0)>;
pub type U17 = Unsigned<(Bit0, Bit1, Bit0, Bit0, Bit0, Bit1)>;
pub type U18 = Unsigned<(Bit0, Bit1, Bit0, Bit0, Bit1, Bit0)>;
pub type U19 = Unsigned<(Bit0, Bit1, Bit0, Bit0, Bit1, Bit1)>;
pub type U20 = Unsigned<(Bit0, Bit1, Bit0, Bit1, Bit0, Bit0)>;
pub type U21 = Unsigned<(Bit0, Bit1, Bit0, Bit1, Bit0, Bit1)>;
pub type U22 = Unsigned<(Bit0, Bit1, Bit0, Bit1, Bit1, Bit0)>;
pub type U23 = Unsigned<(Bit0, Bit1, Bit0, Bit1, Bit1, Bit1)>;
pub type U24 = Unsigned<(Bit0, Bit1, Bit1, Bit0, Bit0, Bit0)>;
pub type U25 = Unsigned<(Bit0, Bit1, Bit1, Bit0, Bit0, Bit1)>;
pub type U26 = Unsigned<(Bit0, Bit1, Bit1, Bit0, Bit1, Bit0)>;
pub type U27 = Unsigned<(Bit0, Bit1, Bit1, Bit0, Bit1, Bit1)>;
pub type U28 = Unsigned<(Bit0, Bit1, Bit1, Bit1, Bit0, Bit0)>;
pub type U29 = Unsigned<(Bit0, Bit1, Bit1, Bit1, Bit0, Bit1)>;
pub type U30 = Unsigned<(Bit0, Bit1, Bit1, Bit1, Bit1, Bit0)>;
pub type U31 = Unsigned<(Bit0, Bit1, Bit1, Bit1, Bit1, Bit1)>;
pub type U32 = Unsigned<(Bit1, Bit0, Bit0, Bit0, Bit0, Bit0)>;
pub type U33 = Unsigned<(Bit1, Bit0, Bit0, Bit0, Bit0, Bit1)>;
#[doc(hidden)]
pub trait CompareBit<HigherBitOrd, Right> {
type Output;
}
impl CompareBit<TEqual, Bit1> for Bit0 {
type Output = TLess;
}
impl<This> CompareBit<TEqual, This> for This {
type Output = TEqual;
}
impl CompareBit<TEqual, Bit0> for Bit1 {
type Output = TGreater;
}
impl<This, Other> CompareBit<TLess, Other> for This {
type Output = TLess;
}
impl<This, Other> CompareBit<TGreater, Other> for This {
type Output = TGreater;
}
impl<L0, R0, T0, L1, R1, T1, L2, R2, T2, L3, R3, T3, L4, R4, T4, L5, R5, T5>
Compare<Unsigned<(R0, R1, R2, R3, R4, R5)>> for Unsigned<(L0, L1, L2, L3, L4, L5)>
where
L0: CompareBit<TEqual, R0, Output = T0>,
L1: CompareBit<T0, R1, Output = T1>,
L2: CompareBit<T1, R2, Output = T2>,
L3: CompareBit<T2, R3, Output = T3>,
L4: CompareBit<T3, R4, Output = T4>,
L5: CompareBit<T4, R5, Output = T5>,
{
type Output = T5;
}
impl<B5, B4, B3, B2, B1, B0> ToUsize for Unsigned<(B5, B4, B3, B2, B1, B0)>
where
B5: IsBit,
B4: IsBit,
B3: IsBit,
B2: IsBit,
B1: IsBit,
B0: IsBit,
{
const USIZE: usize = {
((B5::VALUE as usize) << 5)
| ((B4::VALUE as usize) << 4)
| ((B3::VALUE as usize) << 3)
| ((B2::VALUE as usize) << 2)
| ((B1::VALUE as usize) << 1)
| (B0::VALUE as usize)
};
}