tola_caps/trie/capability.rs
1use crate::primitives::nibble::Nibble;
2use crate::primitives::stream::HashStream;
3use crate::primitives::GetTail;
4use crate::primitives::Peano;
5
6/// Capability Trait
7///
8/// Implemented by unit structs representing capabilities.
9pub trait Capability: 'static {
10 /// Type-level nibble stream responsible for Routing (Trie Path).
11 /// This is typically a short hash (64-bit) of the identity.
12 type Stream: HashStream;
13
14 /// Unique Type-Level Identity.
15 /// Typically a Tuple of `Char` types representing the full name.
16 /// Used for collision resolution (Equality checks) in leaf nodes.
17 type Identity: ?Sized + 'static;
18
19 /// Helper to get the stream head at depth D (used for trie building)
20 type At<D: Peano>: Nibble
21 where
22 Self::Stream: GetTail<D>;
23}
24
25// -----------------------------------------------------------------------------
26// Macros
27// -----------------------------------------------------------------------------
28
29/// Macro to implement Capability for a struct manually (testing only)
30#[macro_export]
31macro_rules! impl_capability {
32 ($name:ty, $id:expr) => {
33 // We cannot easily macro-generate the raw byte stream here without proc-macro.
34 // So for manual impls, we might fallback to just Hash or a simplified stream.
35 // For now, this is a placeholder or requires the user to define the full type.
36 // Actually, tests usually use derive.
37 // If manual is needed, we need a manual helper.
38 compile_error!("Manual impl_capability! is deprecated. Use #[derive(Capability)] or update macro to support new stream types.");
39 };
40 // Kept for backward compat if tests use it old way
41 ($name:ty, $stream:ty, $identity:ty) => {
42 impl $crate::Capability for $name {
43 type Stream = $stream;
44 type Identity = $identity;
45 type At<D: $crate::Peano> = <<Self::Stream as $crate::GetTail<D>>::Out as $crate::HashStream>::Head
46 where Self::Stream: $crate::GetTail<D>;
47 }
48 };
49}