Skip to main content

DerivationTree

Struct DerivationTree 

Source
pub struct DerivationTree<const N: usize = DEFAULT_CAP_TABLE_CAPACITY> { /* private fields */ }
Expand description

Derivation tree for tracking parent-child capability relationships.

Fixed-size array indexed by slot index. No heap allocation.

Implementations§

Source§

impl<const N: usize> DerivationTree<N>

Source

pub const fn new() -> Self

Creates a new empty derivation tree.

Source

pub const fn len(&self) -> usize

Returns the number of active nodes.

Source

pub const fn is_empty(&self) -> bool

Returns true if the tree has no active nodes.

Source

pub fn add_root(&mut self, index: u32, epoch: u64) -> CapResult<()>

Registers a root capability in the tree.

§Errors

Returns CapError::TreeFull if the index is out of bounds.

Source

pub fn add_child( &mut self, parent_index: u32, child_index: u32, depth: u8, epoch: u64, ) -> CapResult<()>

Registers a derived capability in the tree, linking it to its parent.

§Errors

Returns CapError::TreeFull if either index is out of bounds. Returns CapError::Revoked if the parent node has been revoked.

Source

pub fn revoke(&mut self, index: u32) -> CapResult<usize>

Revokes a node and all its descendants. Returns the count of revoked nodes.

§Errors

Returns CapError::InvalidHandle if the index is out of bounds. Returns CapError::Revoked if the node has already been revoked.

Source

pub fn depth(&self, index: u32) -> CapResult<u8>

Returns the depth of the node at the given index.

§Errors

Returns CapError::InvalidHandle if the index is invalid or the node is revoked.

Source

pub fn is_valid(&self, index: u32) -> bool

Returns true if the node at the given index is valid.

Source

pub fn get(&self, index: u32) -> Option<&DerivationNode>

Returns a reference to a node by index.

Source

pub fn collect_subtree(&self, index: u32) -> [u32; N]

Collect all valid indices in the subtree rooted at index.

Returns a fixed-size array of indices (up to N). This is used by revocation to synchronize the capability table.

Uses an iterative stack to avoid stack overflow on wide trees.

Source

pub fn find_parent(&self, child_index: u32) -> Option<u32>

Find the parent of a given node.

Uses the cached parent_index field for O(1) lookup. Falls back to O(N) scan if the cached index is stale (should not happen in normal operation).

Returns None for root nodes or if the parent is not found.

Trait Implementations§

Source§

impl<const N: usize> Default for DerivationTree<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for DerivationTree<N>

§

impl<const N: usize> RefUnwindSafe for DerivationTree<N>

§

impl<const N: usize> Send for DerivationTree<N>
where [DerivationNode; N]: Send,

§

impl<const N: usize> Sync for DerivationTree<N>
where [DerivationNode; N]: Sync,

§

impl<const N: usize> Unpin for DerivationTree<N>

§

impl<const N: usize> UnsafeUnpin for DerivationTree<N>

§

impl<const N: usize> UnwindSafe for DerivationTree<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.