tola-caps 0.2.0

Capability system enabling type-level state tracking, trait detection, and stable specialization.
Documentation
//! AutoCapSet: Capability set for concrete types.
//!
//! # Usage
//!
//! - Concrete types: `Cap<T>` provides type-level capability queries
//! - Generic functions: Use `caps_check!(T: Clone)` macro instead

use crate::primitives::Bool;
use crate::trie::{Capability, InsertAt};
use crate::primitives::stream::D0;

// =============================================================================
// AutoCapSet Trait
// =============================================================================

/// Provides a type-level capability set for a type.
pub trait AutoCapSet {
    /// The Trie type (Empty, Leaf, or Node16).
    type Out;
}

/// Access T's capability set. Requires T: AutoCapSet.
pub type Cap<T> = <T as AutoCapSet>::Out;

// =============================================================================
// InsertIf - Conditional insertion based on const bool
// =============================================================================

/// Insert capability into set if condition is true.
pub trait InsertIf<Cap, const B: bool> {
    type Out;
}

impl<S, Cap> InsertIf<Cap, true> for S
where
    Cap: Capability,
    S: InsertAt<Cap, D0>,
{
    type Out = <S as InsertAt<Cap, D0>>::Out;
}

impl<S, Cap> InsertIf<Cap, false> for S {
    type Out = S;
}

/// Insert based on type-level Bool (Present/Absent).
pub trait InsertIfType<Cap, B: Bool> {
    type Out;
}

impl<S, Cap, B> InsertIfType<Cap, B> for S
where
    B: Bool,
    S: InsertAt<Cap, D0>,
{
    type Out = B::If<<S as InsertAt<Cap, D0>>::Out, S>;
}

// =============================================================================
// Macros (generated by proc-macros)
// =============================================================================

macros::define_impl_auto_caps_macro!();
macros::define_impl_std_types_macro!();

#[cfg(feature = "alloc")]
macros::define_impl_alloc_types_macro!();

#[cfg(feature = "std")]
macros::define_impl_std_lib_types_macro!();

// =============================================================================
// Apply type implementations
// =============================================================================

impl_std_types!();

#[cfg(feature = "alloc")]
impl_alloc_types!();

#[cfg(feature = "std")]
impl_std_lib_types!();