/// A type-level boolean suitable to select conditional trait implementations. /// Implementors are [True] and [False] pub trait TLBool {} /// [TLBool] value of `true`. The opposite is [False] pub struct TLTrue; impl TLBool for TLTrue {} /// [TLBool] value of `false`. The opposite is [True] pub struct TLFalse; impl TLBool for TLFalse {} /// A type that implements [Extends] or a root. Used to select implementations /// of traits on the hierarchy pub trait InHierarchy: Clone { /// Indicates that this hierarchy element is a leaf. Leaves can never have /// children type IsLeaf: TLBool; /// Indicates that this hierarchy element is a root. Roots can never have /// parents type IsRoot: TLBool; } /// A type that derives from a parent type. pub trait Extends: InHierarchy + Into { /// Specify the immediate parent of this type. This guides the type Parent: InHierarchy + TryInto + UnderRootImpl<::IsRoot>; } pub trait UnderRootImpl: Sized { type __Root: UnderRoot; fn __into_root(self) -> Self::__Root; } pub trait UnderRoot: InHierarchy { type Root: UnderRoot; fn into_root(self) -> Self::Root; } impl> UnderRoot for T { type Root = ::IsRoot>>::__Root; fn into_root(self) -> Self::Root { self.__into_root() } } impl> UnderRootImpl for T { type __Root = Self; fn __into_root(self) -> Self::__Root { self } } impl + Extends> UnderRootImpl for T { type __Root = <::Parent as UnderRootImpl< <::Parent as InHierarchy>::IsRoot, >>::__Root; fn __into_root(self) -> Self::__Root { ::Parent>>::into(self).into_root() } }