tola_caps/detect/
autocaps.rs

1//! AutoCapSet: Capability set for concrete types.
2//!
3//! # Usage
4//!
5//! - Concrete types: `Cap<T>` provides type-level capability queries
6//! - Generic functions: Use `caps_check!(T: Clone)` macro instead
7
8use crate::primitives::Bool;
9use crate::trie::{Capability, InsertAt};
10use crate::primitives::stream::D0;
11
12// =============================================================================
13// AutoCapSet Trait
14// =============================================================================
15
16/// Provides a type-level capability set for a type.
17pub trait AutoCapSet {
18    /// The Trie type (Empty, Leaf, or Node16).
19    type Out;
20}
21
22/// Access T's capability set. Requires T: AutoCapSet.
23pub type Cap<T> = <T as AutoCapSet>::Out;
24
25// =============================================================================
26// InsertIf - Conditional insertion based on const bool
27// =============================================================================
28
29/// Insert capability into set if condition is true.
30pub trait InsertIf<Cap, const B: bool> {
31    type Out;
32}
33
34impl<S, Cap> InsertIf<Cap, true> for S
35where
36    Cap: Capability,
37    S: InsertAt<Cap, D0>,
38{
39    type Out = <S as InsertAt<Cap, D0>>::Out;
40}
41
42impl<S, Cap> InsertIf<Cap, false> for S {
43    type Out = S;
44}
45
46/// Insert based on type-level Bool (Present/Absent).
47pub trait InsertIfType<Cap, B: Bool> {
48    type Out;
49}
50
51impl<S, Cap, B> InsertIfType<Cap, B> for S
52where
53    B: Bool,
54    S: InsertAt<Cap, D0>,
55{
56    type Out = B::If<<S as InsertAt<Cap, D0>>::Out, S>;
57}
58
59// =============================================================================
60// Macros (generated by proc-macros)
61// =============================================================================
62
63macros::define_impl_auto_caps_macro!();
64macros::define_impl_std_types_macro!();
65
66#[cfg(feature = "alloc")]
67macros::define_impl_alloc_types_macro!();
68
69#[cfg(feature = "std")]
70macros::define_impl_std_lib_types_macro!();
71
72// =============================================================================
73// Apply type implementations
74// =============================================================================
75
76impl_std_types!();
77
78#[cfg(feature = "alloc")]
79impl_alloc_types!();
80
81#[cfg(feature = "std")]
82impl_std_lib_types!();