tola_caps/trie/
inspect.rs

1//! Runtime inspection of capability sets
2//!
3//! Allows iterating over all capabilities in a set for debugging.
4
5use super::node::{Empty, Leaf, Node16};
6use super::capability::Capability;
7
8/// Runtime inspection of capability sets.
9///
10/// Allows iterating over all capabilities in a set at runtime.
11/// Useful for debugging and logging.
12pub trait Inspect {
13    /// Calls `f` for each capability in the set with its type name.
14    fn inspect<F: FnMut(&'static str)>(&self, f: F);
15}
16
17impl Inspect for Empty {
18    fn inspect<F: FnMut(&'static str)>(&self, _f: F) {}
19}
20
21impl<C: Capability> Inspect for Leaf<C> {
22    fn inspect<F: FnMut(&'static str)>(&self, mut f: F) {
23        f(core::any::type_name::<C>());
24    }
25}
26
27/// Inspect impl for Node16 using #[node16(each_slot)]
28#[macros::node16(each_slot)]
29impl<_Slots_> Inspect for _Node16_
30where
31    each(_Slots_): Inspect + Default,
32{
33    fn inspect<F: FnMut(&'static str)>(&self, mut f: F) {
34        // This line is repeated 16 times with _Slot_ = N0, N1, ..., NF
35        <_Slot_ as Inspect>::inspect(&<_Slot_>::default(), &mut f);
36    }
37}