Files
orchid/orchid-api-traits/src/hierarchy.rs
Lawrence Bethlenfalvy 09cfcb1839 partway towards commands
I got very confused and started mucking about with "spawn" when in fact all I needed was the "inline" extension type in orcx that allows the interpreter to expose custom constants.
2026-03-13 16:48:42 +01:00

57 lines
1.9 KiB
Rust

/// 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<IsRoot = TLFalse> + Into<Self::Parent> {
/// Specify the immediate parent of this type. This guides the
type Parent: InHierarchy<IsLeaf = TLFalse>
+ TryInto<Self>
+ UnderRootImpl<<Self::Parent as InHierarchy>::IsRoot>;
}
pub trait UnderRootImpl<IsRoot: TLBool>: Sized {
type __Root: UnderRoot<IsRoot = TLTrue, Root = Self::__Root>;
fn __into_root(self) -> Self::__Root;
}
pub trait UnderRoot: InHierarchy {
type Root: UnderRoot<IsRoot = TLTrue, Root = Self::Root>;
fn into_root(self) -> Self::Root;
}
impl<T: InHierarchy + UnderRootImpl<T::IsRoot>> UnderRoot for T {
type Root = <Self as UnderRootImpl<<Self as InHierarchy>::IsRoot>>::__Root;
fn into_root(self) -> Self::Root { self.__into_root() }
}
impl<T: InHierarchy<IsRoot = TLTrue>> UnderRootImpl<TLTrue> for T {
type __Root = Self;
fn __into_root(self) -> Self::__Root { self }
}
impl<T: InHierarchy<IsRoot = TLFalse> + Extends> UnderRootImpl<TLFalse> for T {
type __Root = <<Self as Extends>::Parent as UnderRootImpl<
<<Self as Extends>::Parent as InHierarchy>::IsRoot,
>>::__Root;
fn __into_root(self) -> Self::__Root {
<Self as Into<<Self as Extends>::Parent>>::into(self).into_root()
}
}