Trait BranchNode

Source
pub trait BranchNode: Node {
    type ChildrenIter<'branch>: DoubleEndedIterator<Item = <Self::Base as Node>::Token> + FusedIterator
       where Self: 'branch;

    // Required methods
    fn first(&self) -> Option<<Self::Base as Node>::Token>;
    fn last(&self) -> Option<<Self::Base as Node>::Token>;
    fn children<'branch>(
        &'branch self,
        arena: &'branch Arena<Self::Base>,
    ) -> Self::ChildrenIter<'branch>;
    fn is_empty(&self) -> bool;
    fn detach_front(
        token: Self::Token,
        arena: &mut Arena<Self::Base>,
    ) -> Option<<Self::Base as Node>::Token>
       where Self: Sized,
             for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>,
             for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug;
    fn detach_back(
        token: Self::Token,
        arena: &mut Arena<Self::Base>,
    ) -> Option<<Self::Base as Node>::Token>
       where Self: Sized,
             for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>,
             for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug;
    fn pop_front(
        token: Self::Token,
        arena: &mut Arena<Self::Base>,
    ) -> Option<<Self::Base as BaseNode>::Representation>
       where Self: Sized,
             for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>,
             for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug;
    fn pop_back(
        token: Self::Token,
        arena: &mut Arena<Self::Base>,
    ) -> Option<<Self::Base as BaseNode>::Representation>
       where Self: Sized,
             for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>,
             for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug;
    fn push_front(
        token: Self::Token,
        arena: &mut Arena<Self::Base>,
        new: <Self::Base as Node>::Token,
    )
       where Self: Sized,
             for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>,
             for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug;
    fn push_back(
        token: Self::Token,
        arena: &mut Arena<Self::Base>,
        new: <Self::Base as Node>::Token,
    )
       where Self: Sized,
             for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>,
             for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug;

    // Provided method
    fn descendants<'branch>(
        &'branch self,
        arena: &'branch Arena<Self::Base>,
    ) -> Descendants<'branch, Self> 
       where Self: Sized,
             for<'base> &'base Self: TryFrom<&'base Self::Base> { ... }
}
Expand description

A node that can have children.

Required Associated Types§

Source

type ChildrenIter<'branch>: DoubleEndedIterator<Item = <Self::Base as Node>::Token> + FusedIterator where Self: 'branch

The iterator returned by children.

Required Methods§

Source

fn first(&self) -> Option<<Self::Base as Node>::Token>

Returns the token of this branch node’s first child.

If this branch node has no children, None is returned.

Source

fn last(&self) -> Option<<Self::Base as Node>::Token>

Returns the token of this branch node’s last child.

If this branch node has no children, None is returned.

Source

fn children<'branch>( &'branch self, arena: &'branch Arena<Self::Base>, ) -> Self::ChildrenIter<'branch>

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

Source

fn is_empty(&self) -> bool

Returns whether this branch node has no children.

Source

fn detach_front( token: Self::Token, arena: &mut Arena<Self::Base>, ) -> Option<<Self::Base as Node>::Token>
where Self: Sized, for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>, for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug,

Detaches this branch node’s first child, returning its token.

If this branch node is empty then there is no child to detach, so None is returned. Otherwise, the child is removed from this branch node’s children, but remains in the arena.

This function is useful if you want to move a node from one parent to another.

This function takes its token as a parameter instead of &mut self as a receiver to avoid having multiple mutable references into the arena at a time.

§See also

The last child may also be detached using detach_back. If this is a BranchNodeDeque, children may also be detached by index using detach.

If you want to remove a child and its descendants from the arena altogether, see pop_front, pop_back, or, if this is a BranchNodeDeque, remove.

Source

fn detach_back( token: Self::Token, arena: &mut Arena<Self::Base>, ) -> Option<<Self::Base as Node>::Token>
where Self: Sized, for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>, for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug,

Detaches this branch node’s last child, returning its token.

If this branch node is empty then there is no child to detach, so None is returned. Otherwise, the child is removed from this branch node’s children, but remains in the arena.

This function is useful if you want to move a node from one parent to another.

This function takes its token as a parameter instead of &mut self as a receiver to avoid having multiple mutable references into the arena at a time.

§See also

The first child may also be detached using detach_front. If this is a BranchNodeDeque, children may also be detached by index using detach.

If you want to remove a child and its descendants from the arena altogether, see pop_front, pop_back, or, if this is a BranchNodeDeque, remove.

Source

fn pop_front( token: Self::Token, arena: &mut Arena<Self::Base>, ) -> Option<<Self::Base as BaseNode>::Representation>
where Self: Sized, for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>, for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug,

Removes this branch node’s first child.

If this branch node is empty then there is no child to remove, so None is returned. Otherwise, the removed node is returned.

This function takes its token as a parameter instead of &mut self as a receiver to avoid having multiple mutable references into the arena at a time.

§See also

The last child may also be removed using pop_back. If this is a BranchNodeDeque, children may also be removed by index using remove.

If you don’t want to remove a child from the arena, but merely make it a root node or move it to another parent, see detach_front, detach_back, or, if this is a BranchNodeDeque, detach.

Source

fn pop_back( token: Self::Token, arena: &mut Arena<Self::Base>, ) -> Option<<Self::Base as BaseNode>::Representation>
where Self: Sized, for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>, for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug,

Removes this branch node’s last child.

If this branch node is empty then there is no child to remove, so None is returned. Otherwise, the removed node is returned.

This function takes its token as a parameter instead of &mut self as a receiver avoid having multiple mutable references into the arena at a time.

§See also

The first child may also be removed using pop_front. If this is a BranchNodeDeque, children may also be removed by index using remove.

If you don’t want to remove a child from the arena, but merely make it a root node or move it to another parent, see detach_front, detach_back, or, if this is a BranchNodeDeque, detach.

Source

fn push_front( token: Self::Token, arena: &mut Arena<Self::Base>, new: <Self::Base as Node>::Token, )
where Self: Sized, for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>, for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug,

Pushes the given new token’s node to the beginning of this branch node’s children.

This function takes its token as a parameter instead of &mut self as a receiver to avoid having multiple mutable references into the arena at a time.

§Panics

This method will panic if the given new token refers to either:

§See also

A child may also be pushed to the end with push_back. If this is a BranchNodeDeque, children may also be inserted by index using insert.

Source

fn push_back( token: Self::Token, arena: &mut Arena<Self::Base>, new: <Self::Base as Node>::Token, )
where Self: Sized, for<'base> &'base mut Self: TryFrom<&'base mut Self::Base>, for<'base> <&'base mut Self as TryFrom<&'base mut Self::Base>>::Error: Debug,

Pushes the given new token’s node to the end of this branch node’s children.

This function takes its token as a parameter instead of &mut self as a receiver to avoid having multiple mutable references into the arena at a time.

§Panics

This method will panic if the given new token refers to either:

§See also

A child may also be pushed to the beginning with push_front. If this is a BranchNodeDeque, children may also be inserted by index using insert. If this is a BranchNodeDeque, children may also be inserted by index using insert.

Provided Methods§

Source

fn descendants<'branch>( &'branch self, arena: &'branch Arena<Self::Base>, ) -> Descendants<'branch, Self>
where Self: Sized, for<'base> &'base Self: TryFrom<&'base Self::Base>,

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

This iterator is a breadth-first traversal of the branch node’s descendants: its children are done first, then those children’s children in the same order, and so on and so on.

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> BranchNode for Branch<BranchData, LeafData>
where BranchData: Debug, LeafData: Debug,

Available on crate feature split only.
Source§

type ChildrenIter<'branch> = ChildrenLinked<'branch, Branch<BranchData, LeafData>> where Self: 'branch

Source§

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

Available on crate features deque and split only.
Source§

type ChildrenIter<'branch> = Copied<Iter<'branch, <<BranchDeque<BranchData, LeafData> as Node>::Base as Node>::Token>> where Self: 'branch

Source§

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

Available on crate feature unified only.
Source§

type ChildrenIter<'branch> = ChildrenLinked<'branch, UnifiedNode<Data>> where Self: 'branch

Source§

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

Available on crate features deque and unified only.
Source§

type ChildrenIter<'branch> = Copied<Iter<'branch, Token<UnifiedNodeDeque<Data>>>> where Self: 'branch