1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Feature flags handled:
// - std: default, enables std library
// - alloc: enables alloc types in no_std
// - specialize: enables specialization macros
//! # tola-caps
//!
//! Capability system using 16-ary type-level trie with hash-stream routing.
//!
//! **Type-level capability system for Rust.**
//!
//! ## Architecture
//!
//! `tola-caps` allows types to act as sets of keys (Capabilities).
//!
//! ### 1. Routing
//! We use a **64-bit FNV-1a Hash** of the capability's name to route it into a 16-ary Radix Trie.
//!
//! ```text
//! Type Name -> FNV Hash (u64) -> Nibble Stream -> Trie Path (Node16)
//! ```
//!
//! ### 2. Identity (Finger Tree)
//! Hash collisions are resolved via **Finger Tree Identities**.
//! Each capability encodes its full path (`Name@file:line:col`) as a Finger Tree:
//!
//! ```text
//! FDeep<Measure, Prefix, Spine, Suffix>
//! | | | |
//! XOR hash First Middle Last
//! (O(1)) 1-4 B bytes 1-4 B
//! ```
//!
//! ### 3. Comparison
//! Three-layer comparison: Measure (O(1)) -> Prefix -> Suffix -> Spine (O(log n))
//!
//! ### 4. Fallback Tricks
//! We use **Autoref/Method Priority** to achieve trait detection and stable specialization.
//!
//! ```text
//! +-------------------------------------------------------------------+
//! | Layer 0: Primitives |
//! | - Nibble (X0-XF), Stream, Identity (Byte/Char), Finger Tree |
//! +-------------------------------------------------------------------+
//! |
//! v
//! +-------------------------------------------------------------------+
//! | Layer 1: Trie Core |
//! | - Node16, Leaf, Bucket (Storage) |
//! | - InsertAt, RemoveAt, Evaluate (Logic) |
//! +-------------------------------------------------------------------+
//! |
//! v
//! +-------------------------------------------------------------------+
//! | Layer 2: User API |
//! | - macros (caps!, caps_check!), AutoCaps, Feature Detection |
//! +-------------------------------------------------------------------+
//! ```
//!
//! ## Features
//!
//! - **O(1) Compile-time Lookup**: Type-level hash-based routing via 16-ary radix trie
//! - **Zero Runtime Overhead**: All capability checks happen at compile time
//! - **Infinite Extensibility**: Define capabilities anywhere, no central registry needed
//! - **Clean API**: No `_` placeholders or turbofish in function signatures
//!
//! ## Quick Start
//!
//! ```ignore
//! use tola_caps::prelude::*;
//!
//! // Define capabilities with derive (auto-generates hash stream)
//! #[derive(Capability)]
//! struct CanRead;
//!
//! #[derive(Capability)]
//! struct CanWrite;
//!
//! // Build capability set
//! type MyCaps = caps![CanRead, CanWrite];
//!
//! // Function with capability requirements
//! fn process<C>()
//! where
//! C: Evaluate<CanRead, Out = Present>,
//! { }
//!
//! // Call with explicit type
//! process::<MyCaps>();
//! ```
// #![cfg_attr(not(test), no_std)] - Handled by top-level attribute
// Allow `::tola_caps` to work inside the crate itself
extern crate self as tola_caps;
extern crate alloc;
// Re-export paste for define_trait_cap! macro
pub use paste;
// =============================================================================
// Layer 0: Primitives (no dependencies)
// =============================================================================
// =============================================================================
// Layer 1: Trie Core
// =============================================================================
// =============================================================================
// Layer 2: Std Trait Detection
// =============================================================================
// TEMPORARILY DISABLED for debugging - this generates massive amounts of code
// Placeholder module when detect is disabled
// =============================================================================
// Layer 3: Specialization Sugar
// =============================================================================
// Syntax macros (dispatch!, specialize_trait!, impl_specialized!)
// =============================================================================
// Re-exports at Crate Root
// =============================================================================
// Re-export core types from trie and primitives at crate root
pub use *;
pub use ;
pub use ;
pub use ;
// Backward compatibility aliases
// Re-export proc-macros
pub use ;
// =============================================================================
// Declarative Macro Bridge for #[derive(Capability)]
// =============================================================================
//
// Three-layer macro architecture to get module_path!() into proc-macros:
// 1. #[derive(Capability)] (proc-macro) generates __impl_capability! call
// 2. __impl_capability! (this decl-macro) expands concat!(module_path!(), ...)
// 3. make_routing_stream! (proc-macro) receives string literal
/// Internal macro bridge - DO NOT USE DIRECTLY.
/// Use #[derive(Capability)] instead.
/// Helper macro to convert concat!() result to proc-macro call
/// Common items for the capability system.