[−][src]Enum trees::rc::RcNode
Reference-counting node.
Variants
Scattered(ScatteredRcNode<T>)
Piled(PiledRcNode<T>)
Implementations
impl<T> RcNode<T>
[src]
pub fn is_root(&self) -> bool
[src]
Checks if it is a root node.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0)/tr(1) ); assert!( root.is_root() ); assert!( !root.front().unwrap().is_root() );
pub fn data(&self) -> Ref<'_, T>
[src]
Dynamically borrows the node's data.
pub fn data_mut(&self) -> RefMut<'_, T>
[src]
Mutably borrows the node's data.
pub unsafe fn node(&self) -> Ref<'_, Node<T>>
[src]
Obtains a node reference
pub unsafe fn node_mut(&self) -> RefMut<'_, Node<T>>
[src]
Obtains a mutable node reference
pub fn has_no_child(&self) -> bool
[src]
Returns true
if this Node
has no child node, otherwise false
.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0)/tr(1) ); assert!( !root.has_no_child() ); assert!( root.front().unwrap().has_no_child() );
pub fn degree(&self) -> usize
[src]
Returns the number of subtrees.
Examples
use trees::{RcNode, Tree}; let root = RcNode::from( Tree::<i32>::from_tuple(( 0, (1,2,3), (4,5,6), ))); assert_eq!( root.degree(), 2 );
pub fn node_count(&self) -> usize
[src]
Returns the number of all subnodes, including itself.
Examples
use trees::{RcNode, Tree}; let root = RcNode::from( Tree::<i32>::from_tuple(( 0, (1,2,3), (4,5,6), ))); assert_eq!( root.node_count(), 7 );
pub fn front(&self) -> Option<RcNode<T>>
[src]
Returns the first child of the tree, or None if it is empty.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0)/tr(1)/tr(2) ); assert_eq!( root.front(), Some( RcNode::from( tr(1) )));
pub fn back(&self) -> Option<RcNode<T>>
[src]
Returns the last child of the tree, or None if it is empty.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0)/tr(1)/tr(2) ); assert_eq!( root.back(), Some( RcNode::from( tr(2) )));
pub fn parent(&self) -> Option<RcNode<T>>
[src]
Returns the parent node of this node, or None if it is the root node.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0)/tr(1) ); assert_eq!( root.parent(), None ); let tr_1 = root.front().unwrap(); assert_eq!( tr_1.parent(), Some( root ));
pub fn push_front(&self, tree: Tree<T>)
[src]
Adds the tree as the first child.
Examples
use trees::{RcNode, Tree}; let root = RcNode::from( Tree::new(0) ); root.push_front( Tree::new(1) ); assert_eq!( root.to_string(), "0( 1 )" ); root.push_front( Tree::new(2) ); assert_eq!( root.to_string(), "0( 2 1 )" );
pub fn push_back(&self, tree: Tree<T>)
[src]
Adds the tree as the last child.
Examples
use trees::{RcNode, Tree}; let root = RcNode::from( Tree::new(0) ); root.push_back( Tree::new(1) ); assert_eq!( root.to_string(), "0( 1 )" ); root.push_back( Tree::new(2) ); assert_eq!( root.to_string(), "0( 1 2 )" );
pub fn pop_front(&self) -> Option<RcNode<T>>
[src]
Removes and return the first child.
Examples
use trees::{RcNode, Tree}; let root = RcNode::from( Tree::<i32>::from_tuple(( 0,1,2 ))); let front = root.pop_front().unwrap(); assert_eq!( front, RcNode::from( Tree::new(1) )); assert_eq!( root.to_string(), "0( 2 )" ); let front = root.pop_front().unwrap(); assert_eq!( front, RcNode::from( Tree::new(2) )); assert_eq!( root.to_string(), "0" );
pub fn pop_back(&self) -> Option<RcNode<T>>
[src]
Removes and return the last child.
Examples
use trees::{RcNode, Tree}; let root = RcNode::from( Tree::<i32>::from_tuple(( 0,1,2 ))); let back = root.pop_back().unwrap(); assert_eq!( back, RcNode::from( Tree::new(2) )); assert_eq!( root.to_string(), "0( 1 )" ); let back = root.pop_back().unwrap(); assert_eq!( back, RcNode::from( Tree::new(1) )); assert_eq!( root.to_string(), "0" );
pub fn prepend(&self, forest: Forest<T>)
[src]
Adds all the forest's trees at front of children list.
Examples
use trees::{Forest, RcNode, Tree, tr}; let root = RcNode::from( Tree::<i32>::from_tuple(( 0, 1, 2 ))); let forest = Forest::<i32>::from_tuple(( 3, 4 )); root.prepend( forest ); assert_eq!( root.to_string(), "0( 3 4 1 2 )" );
pub fn append(&self, forest: Forest<T>)
[src]
Adds all the forest's trees at back of children list.
Examples
use trees::{Forest, RcNode, Tree, tr}; let root = RcNode::from( Tree::<i32>::from_tuple(( 0, 1, 2 ))); let forest = Forest::<i32>::from_tuple(( 3, 4 )); root.append( forest ); assert_eq!( root.to_string(), "0( 1 2 3 4 )" );
pub fn insert_prev_sib(&self, sib: Tree<T>)
[src]
Inserts sib tree before self
.
The newly inserted node will not be iterated over by the currently running iterator.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0) /tr(1)/tr(2) ); for sub in root.iter_rc() { sub.insert_prev_sib( tr(3) ); } assert_eq!( root.to_string(), "0( 3 1 3 2 )" );
pub fn insert_next_sib(&self, sib: Tree<T>)
[src]
Inserts sib tree after self
.
The newly inserted node will not be iterated over by the currently running iterator.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0) /tr(1)/tr(2) ); for sub in root.iter_rc() { sub.insert_next_sib( tr(3) ); } assert_eq!( root.to_string(), "0( 1 3 2 3 )" );
pub fn detach(&self)
[src]
The subtree departs from its parent and becomes an indepent Tree
.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0) /tr(1)/tr(2)/tr(3) ); for sub in root.iter_rc() { sub.detach(); } assert!( root.has_no_child() );
pub fn iter_rc(&self) -> IterRc<T>ⓘ
[src]
Provides a forward iterator over child Node
s, with shared ownership.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0) ); assert_eq!( root.iter_rc().next(), None ); let root = RcNode::from( tr(0) /tr(1)/tr(2) ); let mut iter = root.iter_rc(); assert_eq!( iter.next(), Some( RcNode::from( tr(1) ))); assert_eq!( iter.next(), Some( RcNode::from( tr(2) ))); assert_eq!( iter.next(), None );
pub fn downgrade(&self) -> WeakNode<T>
[src]
Creates a new weak pointer to this node.
pub unsafe fn into_tree(self) -> Tree<T>
[src]
Converts to a tree which disables reference-counting.
Panics
Only root node could be converted, otherwise it panics.
Examples
use trees::{RcNode, Tree, tr}; let root = RcNode::from( tr(0) /( tr(1)/tr(2) )); let tree = unsafe{ root.into_tree() }; assert_eq!( tree, tr(0) /( tr(1)/tr(2) )); let root = RcNode::from( Tree::<i32>::from_tuple(( 0, (1, 2), ))); let tree = unsafe{ root.into_tree() }; assert_eq!( tree, tr(0) /( tr(1)/tr(2) ));
impl<T: Clone> RcNode<T>
[src]
pub fn deep_clone(&self) -> Tree<T>
[src]
Clones the node deeply and creates a new tree.
Examples
use trees::{RcNode, tr}; let root = RcNode::from( tr(0) /( tr(1)/tr(2) )); let new_tree = root.front().unwrap().deep_clone(); assert_eq!( new_tree, tr(1) /tr(2) );
Trait Implementations
impl<T> Clone for RcNode<T>
[src]
impl<T: Debug> Debug for RcNode<T>
[src]
impl<T: Display> Display for RcNode<T>
[src]
impl<T> Drop for RcNode<T>
[src]
impl<T: Eq> Eq for RcNode<T>
[src]
impl<T> Extend<Tree<T>> for RcNode<T>
[src]
fn extend<I: IntoIterator<Item = Tree<T>>>(&mut self, iter: I)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<T> From<Tree<T>> for RcNode<T>
[src]
impl<T: Hash> Hash for RcNode<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: Ord> Ord for RcNode<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq> PartialEq<RcNode<T>> for RcNode<T>
[src]
impl<T: PartialOrd> PartialOrd<RcNode<T>> for RcNode<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for RcNode<T>
[src]
impl<T> !Send for RcNode<T>
[src]
impl<T> !Sync for RcNode<T>
[src]
impl<T> Unpin for RcNode<T>
[src]
impl<T> !UnwindSafe for RcNode<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut Tⓘ
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.