Trait Node

Source
pub trait Node: Debug + Sealed {
    type Base: BaseNode;
    type Token: NodeToken<Self>
       where Self: Sized;
    type Data;
    type DataRef<'data>
       where Self: 'data;
    type DataRefMut<'data>
       where Self: 'data;

    // Required methods
    fn new(arena: &mut Arena<Self::Base>, data: Self::Data) -> Self::Token
       where Self: Sized;
    fn token(&self) -> Self::Token
       where Self: Sized;
    fn parent(
        &self,
    ) -> Option<<<Self::Base as BaseNode>::Branch as Node>::Token>;
    fn data(&self) -> Self::DataRef<'_>;
    fn data_mut(&mut self) -> Self::DataRefMut<'_>;

    // Provided methods
    fn ancestors<'node>(
        &'node self,
        arena: &'node Arena<Self::Base>,
    ) -> Ancestors<'node, Self::Base> 
       where Self: Sized { ... }
    fn root<'node>(
        &'node self,
        arena: &'node Arena<Self::Base>,
    ) -> RootToken<Self>
       where Self: Sized { ... }
}
Expand description

A node in a tree.

Required Associated Types§

Source

type Base: BaseNode

The ‘base node’ used in the arena.

For typed nodes where there is a typed node type in addition to separate branch and leaf types, all of those types will use the typed node type as the ArenaNode.

Source

type Token: NodeToken<Self> where Self: Sized

The token associated with this type of node.

Source

type Data

The custom data associated with this node.

Source

type DataRef<'data> where Self: 'data

A type acting as a reference to the node’s data.

This is the type returned by data.

Source

type DataRefMut<'data> where Self: 'data

A type acting as a mutable reference to the node’s data.

This is the type returned by data_mut.

Required Methods§

Source

fn new(arena: &mut Arena<Self::Base>, data: Self::Data) -> Self::Token
where Self: Sized,

Creates a new node allocated in the given arena using the given data.

The node’s token is returned.

Source

fn token(&self) -> Self::Token
where Self: Sized,

Returns this node’s token.

Source

fn parent(&self) -> Option<<<Self::Base as BaseNode>::Branch as Node>::Token>

Returns the token of this node’s parent.

If this node is the root node of its tree, that means it has no parent and thus None is returned.

Source

fn data(&self) -> Self::DataRef<'_>

Returns a reference to the data associated with this node.

Source

fn data_mut(&mut self) -> Self::DataRefMut<'_>

Returns a mutable reference to the data associated with this node.

Provided Methods§

Source

fn ancestors<'node>( &'node self, arena: &'node Arena<Self::Base>, ) -> Ancestors<'node, Self::Base>
where Self: Sized,

Returns an iterator over the tokens of this node’s ancestors.

This iterator begins with the node’s parent and ends with the root node (i.e. the ancestor with no parent).

Source

fn root<'node>(&'node self, arena: &'node Arena<Self::Base>) -> RootToken<Self>
where Self: Sized,

Returns this node’s root node.

The root node is the most distant ancestor; it is the only node in a tree that does not have a parent.

If this node is the root node, RootToken::This is returned. Otherwise, RootToken::Ancestor is returned with the root node’s token.

Internally, this method iterates over the node’s ancestors to find the last one, so it is O(n) best, average, and worst case.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<BranchData, LeafData> Node for SplitNode<BranchData, LeafData>
where BranchData: Debug, LeafData: Debug,

Available on crate feature split only.
Source§

type Base = SplitNode<BranchData, LeafData>

Source§

type Token = SplitToken<BranchData, LeafData>

Source§

type Data = SplitData<BranchData, LeafData>

Source§

type DataRef<'data> = SplitData<&'data BranchData, &'data LeafData> where Self: 'data

Source§

type DataRefMut<'data> = SplitData<&'data mut BranchData, &'data mut LeafData> where Self: 'data

Source§

impl<BranchData, LeafData> Node for SplitNodeDeque<BranchData, LeafData>
where BranchData: Debug, LeafData: Debug,

Available on crate features deque and split only.
Source§

type Base = SplitNodeDeque<BranchData, LeafData>

Source§

type Token = SplitTokenDeque<BranchData, LeafData>

Source§

type Data = SplitData<BranchData, LeafData>

Source§

type DataRef<'data> = SplitData<&'data BranchData, &'data LeafData> where Self: 'data

Source§

type DataRefMut<'data> = SplitData<&'data mut BranchData, &'data mut LeafData> where Self: 'data

Source§

impl<BranchData, LeafData> Node for Branch<BranchData, LeafData>
where BranchData: Debug, LeafData: Debug,

Available on crate feature split only.
Source§

type Base = SplitNode<BranchData, LeafData>

Source§

type Token = Token<Branch<BranchData, LeafData>>

Source§

type Data = BranchData

Source§

type DataRef<'data> = &'data BranchData where Self: 'data

Source§

type DataRefMut<'data> = &'data mut BranchData where Self: 'data

Source§

impl<BranchData, LeafData> Node for BranchDeque<BranchData, LeafData>
where BranchData: Debug, LeafData: Debug,

Available on crate features deque and split only.
Source§

type Base = SplitNodeDeque<BranchData, LeafData>

Source§

type Token = Token<BranchDeque<BranchData, LeafData>>

Source§

type Data = BranchData

Source§

type DataRef<'data> = &'data BranchData where Self: 'data

Source§

type DataRefMut<'data> = &'data mut BranchData where Self: 'data

Source§

impl<BranchData, LeafData> Node for Leaf<BranchData, LeafData>
where BranchData: Debug, LeafData: Debug,

Available on crate feature split only.
Source§

type Base = SplitNode<BranchData, LeafData>

Source§

type Token = Token<Leaf<BranchData, LeafData>>

Source§

type Data = LeafData

Source§

type DataRef<'data> = &'data LeafData where Self: 'data

Source§

type DataRefMut<'data> = &'data mut LeafData where Self: 'data

Source§

impl<BranchData, LeafData> Node for LeafDeque<BranchData, LeafData>
where BranchData: Debug, LeafData: Debug,

Available on crate features deque and split only.
Source§

type Base = SplitNodeDeque<BranchData, LeafData>

Source§

type Token = Token<LeafDeque<BranchData, LeafData>>

Source§

type Data = LeafData

Source§

type DataRef<'data> = &'data LeafData where Self: 'data

Source§

type DataRefMut<'data> = &'data mut LeafData where Self: 'data

Source§

impl<Data: Debug> Node for UnifiedNode<Data>

Available on crate feature unified only.
Source§

type Base = UnifiedNode<Data>

Source§

type Token = Token<UnifiedNode<Data>>

Source§

type Data = Data

Source§

type DataRef<'data> = &'data Data where Self: 'data

Source§

type DataRefMut<'data> = &'data mut Data where Self: 'data

Source§

impl<Data: Debug> Node for UnifiedNodeDeque<Data>

Available on crate features deque and unified only.
Source§

type Base = UnifiedNodeDeque<Data>

Source§

type Token = Token<UnifiedNodeDeque<Data>>

Source§

type Data = Data

Source§

type DataRef<'data> = &'data Data where Self: 'data

Source§

type DataRefMut<'data> = &'data mut Data where Self: 'data