Struct dendron::FrozenNode
source · [−]pub struct FrozenNode<T> { /* private fields */ }
Expand description
A Node
with a tree hierarchy edit prohibition bundled.
FrozenNode
can be created by Node::bundle_hierarchy_edit_prohibition
or
Node::bundle_new_hierarchy_edit_prohibition
.
Panics
Panics if the number of active edit prohibitions through this node is
usize::MAX
. This is very unlikely to happen without leaking prohibitions.
Implementations
sourceimpl<T> FrozenNode<T>
impl<T> FrozenNode<T>
sourceimpl<T> FrozenNode<T>
impl<T> FrozenNode<T>
Tree hierarchy edit prohibitions.
sourcepub fn extract_hierarchy_edit_prohibition(&self) -> HierarchyEditProhibition<T>
pub fn extract_hierarchy_edit_prohibition(&self) -> HierarchyEditProhibition<T>
Returns a copy of the tree hierarchy edit prohibition.
Examples
use dendron::{FrozenNode, Node};
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
let prohibition = frozen.extract_hierarchy_edit_prohibition();
sourceimpl<T> FrozenNode<T>
impl<T> FrozenNode<T>
Data access.
sourcepub fn try_borrow_data(&self) -> Result<Ref<'_, T>, BorrowError>
pub fn try_borrow_data(&self) -> Result<Ref<'_, T>, BorrowError>
Returns a reference to the data associated to the node.
Failures
Fails if the data is currently mutably (i.e. exclusively) borrowed.
Examples
use dendron::Node;
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
assert_eq!(
*frozen
.try_borrow_data()
.expect("should not fail since not mutably borrowed from other place"),
"root"
);
sourcepub fn borrow_data(&self) -> Ref<'_, T>
pub fn borrow_data(&self) -> Ref<'_, T>
Returns a reference to the data associated to the node.
Panics
Panics if the data is already mutably borrowed.
Examples
use dendron::Node;
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
assert_eq!(*frozen.borrow_data(), "root");
sourcepub fn try_borrow_data_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
pub fn try_borrow_data_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
Returns a mutable reference to the data associated to the node.
Examples
use dendron::Node;
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
*frozen
.try_borrow_data_mut()
.expect("should not fail since not borrowed from other place")
= "ROOT";
assert_eq!(*frozen.borrow_data(), "ROOT");
sourcepub fn borrow_data_mut(&self) -> RefMut<'_, T>
pub fn borrow_data_mut(&self) -> RefMut<'_, T>
Returns a mutable reference to the data associated to the node.
Panics
Panics if the data is already mutably borrowed.
Examples
use dendron::Node;
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
*frozen.borrow_data_mut() = "ROOT";
assert_eq!(*frozen.borrow_data(), "ROOT");
sourcepub fn ptr_eq(&self, other: &Self) -> bool
pub fn ptr_eq(&self, other: &Self) -> bool
Returns true
if the two FrozenNode
s point to the same allocation.
Examples
use dendron::Node;
let frozen1 = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
let frozen2 = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
assert!(frozen1.ptr_eq(&frozen1));
assert!(frozen1 == frozen2, "same content and hierarchy");
assert!(
!frozen1.ptr_eq(&frozen2),
"same content and hierarchy but different allocation"
);
sourceimpl<T> FrozenNode<T>
impl<T> FrozenNode<T>
Neighbor nodes accessor.
sourcepub fn tree(&self) -> Tree<T>
pub fn tree(&self) -> Tree<T>
Returns the tree the node belongs to.
Examples
use dendron::Node;
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
let tree = frozen.tree();
assert!(tree.root().ptr_eq(&frozen.plain()));
sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Returns true if the node is the root.
Examples
use dendron::Node;
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
assert!(frozen.is_root());
sourcepub fn belongs_to(&self, tree: &Tree<T>) -> bool
pub fn belongs_to(&self, tree: &Tree<T>) -> bool
Returns true if the node belongs to the given tree.
Examples
use dendron::Node;
let frozen1 = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
let frozen2 = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
assert!(frozen1.belongs_to(&frozen1.tree()));
assert!(!frozen1.belongs_to(&frozen2.tree()));
sourcepub fn belongs_to_same_tree(&self, other: &Self) -> bool
pub fn belongs_to_same_tree(&self, other: &Self) -> bool
Returns true if the given node belong to the same tree.
Examples
use dendron::Node;
let frozen1 = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
let frozen2 = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
assert!(!frozen1.belongs_to_same_tree(&frozen2));
sourcepub fn root(&self) -> Self
pub fn root(&self) -> Self
Returns the hot root node.
Examples
use dendron::Node;
let frozen = Node::new_tree("root")
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
assert!(frozen.root().ptr_eq(&frozen));
sourcepub fn parent(&self) -> Option<Self>
pub fn parent(&self) -> Option<Self>
Returns the parent node.
See Node::parent
for usage examples.
sourcepub fn prev_sibling(&self) -> Option<Self>
pub fn prev_sibling(&self) -> Option<Self>
Returns the previous sibling.
See Node::prev_sibling
for usage examples.
sourcepub fn next_sibling(&self) -> Option<Self>
pub fn next_sibling(&self) -> Option<Self>
Returns the next sibling.
See Node::next_sibling
for usage examples.
sourcepub fn first_sibling(&self) -> Self
pub fn first_sibling(&self) -> Self
Returns the first sibling.
See Node::first_sibling
for usage examples.
sourcepub fn last_sibling(&self) -> Self
pub fn last_sibling(&self) -> Self
Returns the last sibling.
See Node::last_sibling
for usage examples.
sourcepub fn first_last_sibling(&self) -> (Self, Self)
pub fn first_last_sibling(&self) -> (Self, Self)
Returns the first and the last siblings.
See Node::first_last_sibling
for usage examples.
sourcepub fn first_child(&self) -> Option<Self>
pub fn first_child(&self) -> Option<Self>
Returns the first child node.
See Node::first_child
for usage examples.
sourcepub fn last_child(&self) -> Option<Self>
pub fn last_child(&self) -> Option<Self>
Returns the last child node.
See Node::last_child
for usage examples.
sourcepub fn first_last_child(&self) -> Option<(Self, Self)>
pub fn first_last_child(&self) -> Option<(Self, Self)>
Returns links to the first and the last child nodes.
See Node::first_last_child
for usage examples.
sourcepub fn has_prev_sibling(&self) -> bool
pub fn has_prev_sibling(&self) -> bool
Returns true if the previous sibling exists.
See Node::has_prev_sibling
for usage examples.
sourcepub fn has_next_sibling(&self) -> bool
pub fn has_next_sibling(&self) -> bool
Returns true if the next sibling exists.
See Node::has_prev_sibling
for usage examples.
sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if the node has any children.
See Node::has_children
for usage examples.
sourcepub fn num_children(&self) -> usize
pub fn num_children(&self) -> usize
sourcepub fn has_one_child(&self) -> bool
👎 Deprecated since 0.1.1: use HotNode::num_children
pub fn has_one_child(&self) -> bool
use HotNode::num_children
Returns true if the node has just one child.
Use num_children
method instead, i.e. use
self.num_children() == 1
.
See Node::has_one_child
for usage examples.
sourcepub fn has_multiple_children(&self) -> bool
👎 Deprecated since 0.1.1: use HotNode::num_children
pub fn has_multiple_children(&self) -> bool
use HotNode::num_children
Returns true if the node has two or more children.
Use num_children
method instead, i.e. use
self.num_children() > 1
.
See Node::has_multiple_children
for usage examples.
sourcepub fn count_children(&self) -> usize
👎 Deprecated since 0.1.1: use HotNode::num_children
pub fn count_children(&self) -> usize
use HotNode::num_children
Returns the number of children.
Use num_children
method instead.
See Node::count_children
for usage examples.
sourcepub fn count_preceding_siblings(&self) -> usize
pub fn count_preceding_siblings(&self) -> usize
Returns the number of preceding siblings.
Note that this is O(N) operation.
See Node::count_preceding_siblings
for usage examples.
sourcepub fn count_following_siblings(&self) -> usize
pub fn count_following_siblings(&self) -> usize
Returns the number of following siblings.
Note that this is O(N) operation.
See Node::count_following_siblings
for usage examples.
sourcepub fn count_ancestors(&self) -> usize
pub fn count_ancestors(&self) -> usize
Returns the number of ancestors.
Note that this is O(N) operation.
See Node::count_ancestors
for usage examples.
sourceimpl<T> FrozenNode<T>
impl<T> FrozenNode<T>
Tree traverser.
sourcepub fn depth_first_traverse(&self) -> DepthFirstTraverser<T>ⓘNotable traits for DepthFirstTraverser<T>impl<T> Iterator for DepthFirstTraverser<T> type Item = DftEvent<Node<T>>;
pub fn depth_first_traverse(&self) -> DepthFirstTraverser<T>ⓘNotable traits for DepthFirstTraverser<T>impl<T> Iterator for DepthFirstTraverser<T> type Item = DftEvent<Node<T>>;
Returns the depth-first traverser.
See Node::depth_first_traverse
for usage examples.
sourcepub fn depth_first_reverse_traverse(&self) -> ReverseDepthFirstTraverser<T>ⓘNotable traits for ReverseDepthFirstTraverser<T>impl<T> Iterator for ReverseDepthFirstTraverser<T> type Item = DftEvent<Node<T>>;
pub fn depth_first_reverse_traverse(&self) -> ReverseDepthFirstTraverser<T>ⓘNotable traits for ReverseDepthFirstTraverser<T>impl<T> Iterator for ReverseDepthFirstTraverser<T> type Item = DftEvent<Node<T>>;
Returns the reverse depth-first traverser.
See Node::depth_first_reverse_traverse
for usage examples.
sourcepub fn children(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
pub fn children(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
Returns the children traverser.
See Node::children
for usage examples.
sourcepub fn children_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
pub fn children_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
Returns the reverse children traverser.
See Node::children_reverse
for usage examples.
sourcepub fn ancestors(&self) -> AncestorsTraverser<T>ⓘNotable traits for AncestorsTraverser<T>impl<T> Iterator for AncestorsTraverser<T> type Item = Node<T>;
pub fn ancestors(&self) -> AncestorsTraverser<T>ⓘNotable traits for AncestorsTraverser<T>impl<T> Iterator for AncestorsTraverser<T> type Item = Node<T>;
Returns the ancestors traverser.
See Node::ancestors
for usage examples.
sourcepub fn ancestors_or_self(&self) -> AncestorsTraverser<T>ⓘNotable traits for AncestorsTraverser<T>impl<T> Iterator for AncestorsTraverser<T> type Item = Node<T>;
pub fn ancestors_or_self(&self) -> AncestorsTraverser<T>ⓘNotable traits for AncestorsTraverser<T>impl<T> Iterator for AncestorsTraverser<T> type Item = Node<T>;
Returns the ancestors traverser.
See Node::ancestors_or_self
for usage examples.
sourcepub fn siblings(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
pub fn siblings(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
Returns the siblings traverser.
See Node::siblings
for usage examples.
sourcepub fn siblings_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
pub fn siblings_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
Returns the reverse siblings traverser.
See Node::siblings_reverse
for usage examples.
sourcepub fn preceding_siblings_or_self_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
pub fn preceding_siblings_or_self_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
Returns the preceding siblings traverser.
See Node::preceding_siblings_or_self_reverse
for usage examples.
sourcepub fn preceding_siblings_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
pub fn preceding_siblings_reverse(&self) -> ReverseSiblingsTraverser<T>ⓘNotable traits for ReverseSiblingsTraverser<T>impl<T> Iterator for ReverseSiblingsTraverser<T> type Item = Node<T>;
Returns the preceding siblings traverser.
See Node::preceding_siblings_reverse
for usage examples.
sourcepub fn following_siblings_or_self(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
pub fn following_siblings_or_self(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
Returns the following siblings traverser.
See Node::following_siblings_or_self
for usage examples.
sourcepub fn following_siblings(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
pub fn following_siblings(&self) -> SiblingsTraverser<T>ⓘNotable traits for SiblingsTraverser<T>impl<T> Iterator for SiblingsTraverser<T> type Item = Node<T>;
Returns the following siblings traverser.
See Node::following_siblings
for usage examples.
sourcepub fn depth_first_traverse_stable(&self) -> StableDepthFirstTraverser<T>ⓘNotable traits for StableDepthFirstTraverser<T>impl<T> Iterator for StableDepthFirstTraverser<T> type Item = DftEvent<FrozenNode<T>>;
pub fn depth_first_traverse_stable(&self) -> StableDepthFirstTraverser<T>ⓘNotable traits for StableDepthFirstTraverser<T>impl<T> Iterator for StableDepthFirstTraverser<T> type Item = DftEvent<FrozenNode<T>>;
Returns the stable double-ended depth-first traverser.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
See Node::depth_first_traverse
for usage examples.
sourcepub fn children_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
pub fn children_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
Returns the stable double-ended children traverser.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
See Node::children
for usage examples.
sourcepub fn siblings_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
pub fn siblings_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
Returns the stable siblings traverser.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
See Node::siblings
for usage examples.
sourcepub fn preceding_siblings_or_self_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
pub fn preceding_siblings_or_self_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
Returns the stable preceding siblings traverser.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
sourcepub fn preceding_siblings_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
pub fn preceding_siblings_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
Returns the stable preceding siblings traverser.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
sourcepub fn following_siblings_or_self_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
pub fn following_siblings_or_self_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
Returns the stable following siblings traverser.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
sourcepub fn following_siblings_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
pub fn following_siblings_stable(&self) -> StableSiblingsTraverser<T>ⓘNotable traits for StableSiblingsTraverser<T>impl<T> Iterator for StableSiblingsTraverser<T> type Item = FrozenNode<T>;
Returns the stable following siblings traverser.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
sourcepub fn shallow_depth_first_traverse_stable(
&self,
max_depth: Option<usize>
) -> StableShallowDepthFirstTraverser<T>ⓘNotable traits for StableShallowDepthFirstTraverser<T>impl<T> Iterator for StableShallowDepthFirstTraverser<T> type Item = DftEvent<(FrozenNode<T>, usize)>;
pub fn shallow_depth_first_traverse_stable(
&self,
max_depth: Option<usize>
) -> StableShallowDepthFirstTraverser<T>ⓘNotable traits for StableShallowDepthFirstTraverser<T>impl<T> Iterator for StableShallowDepthFirstTraverser<T> type Item = DftEvent<(FrozenNode<T>, usize)>;
Returns the stable depth-first traverser that can limit the depth to iterate.
If None
is passed as max_depth
, then the iterator traverses nodes
in unlimited depth.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
Examples
use dendron::tree_node;
use dendron::traverse::DftEvent;
let frozen = tree_node! {
"root", [
/("0", [
/("0-0", ["0-0-0", "0-0-1"]),
"0-1",
/("0-2", ["0-2-0"]),
]),
/("1", [
"1-0",
]),
"2",
]
}
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
// root
// |-- 0
// | |-- 0-0
// | | |-- 0-0-0
// | | `-- 0-0-1
// | |-- 0-1
// | `-- 0-2
// | `-- 0-2-0
// |-- 1
// | `-- 1-0
// `-- 2
let max0 = frozen.shallow_depth_first_traverse_stable(Some(0))
.map(|ev| ev.map(|(node, depth)| (*node.borrow_data(), depth)))
.collect::<Vec<_>>();
assert_eq!(
max0,
&[
DftEvent::Open(("root", 0)),
DftEvent::Close(("root", 0)),
]
);
let max2 = frozen.shallow_depth_first_traverse_stable(Some(2))
.map(|ev| ev.map(|(node, depth)| (*node.borrow_data(), depth)))
.collect::<Vec<_>>();
assert_eq!(
max2,
&[
DftEvent::Open(("root", 0)),
DftEvent::Open(("0", 1)),
DftEvent::Open(("0-0", 2)),
DftEvent::Close(("0-0", 2)),
DftEvent::Open(("0-1", 2)),
DftEvent::Close(("0-1", 2)),
DftEvent::Open(("0-2", 2)),
DftEvent::Close(("0-2", 2)),
DftEvent::Close(("0", 1)),
DftEvent::Open(("1", 1)),
DftEvent::Open(("1-0", 2)),
DftEvent::Close(("1-0", 2)),
DftEvent::Close(("1", 1)),
DftEvent::Open(("2", 1)),
DftEvent::Close(("2", 1)),
DftEvent::Close(("root", 0)),
]
);
let max_unlimited = frozen.shallow_depth_first_traverse_stable(None)
.map(|ev| ev.map(|(node, _depth)| *node.borrow_data()))
.collect::<Vec<_>>();
let all = frozen.depth_first_traverse()
.map(|ev| ev.map(|node| *node.borrow_data()))
.collect::<Vec<_>>();
assert_eq!(max_unlimited, all);
sourcepub fn non_allocating_breadth_first_traverse_stable(
&self,
start_depth: usize
) -> NonAllocatingBreadthFirstTraverser<T>ⓘNotable traits for NonAllocatingBreadthFirstTraverser<T>impl<T> Iterator for NonAllocatingBreadthFirstTraverser<T> type Item = (FrozenNode<T>, usize);
pub fn non_allocating_breadth_first_traverse_stable(
&self,
start_depth: usize
) -> NonAllocatingBreadthFirstTraverser<T>ⓘNotable traits for NonAllocatingBreadthFirstTraverser<T>impl<T> Iterator for NonAllocatingBreadthFirstTraverser<T> type Item = (FrozenNode<T>, usize);
Returns the stable non-allocating breadth-first traverser.
Note that traversing all nodes will be O(n^2)
operation in worst case,
not O(n)
.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
Examples
use dendron::tree_node;
use dendron::traverse::DftEvent;
let frozen = tree_node! {
"root", [
/("0", [
/("0-0", ["0-0-0", "0-0-1"]),
"0-1",
/("0-2", ["0-2-0"]),
]),
/("1", [
"1-0",
]),
"2",
]
}
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
// root
// |-- 0
// | |-- 0-0
// | | |-- 0-0-0
// | | `-- 0-0-1
// | |-- 0-1
// | `-- 0-2
// | `-- 0-2-0
// |-- 1
// | `-- 1-0
// `-- 2
let depth2 = frozen
.non_allocating_breadth_first_traverse_stable(2)
.map(|(node, depth)| (*node.borrow_data(), depth))
.collect::<Vec<_>>();
assert_eq!(
depth2,
&[
("0-0", 2), ("0-1", 2), ("0-2", 2), ("1-0", 2),
("0-0-0", 3), ("0-0-1", 3), ("0-2-0", 3)
]
);
let all = frozen
.non_allocating_breadth_first_traverse_stable(0)
.map(|(node, depth)| (*node.borrow_data(), depth))
.collect::<Vec<_>>();
assert_eq!(
all,
&[
("root", 0),
("0", 1), ("1", 1), ("2", 1),
("0-0", 2), ("0-1", 2), ("0-2", 2), ("1-0", 2),
("0-0-0", 3), ("0-0-1", 3), ("0-2-0", 3)
]
);
sourcepub fn allocating_breadth_first_traverse_stable(
&self,
start_depth: usize
) -> AllocatingBreadthFirstTraverser<T>ⓘNotable traits for AllocatingBreadthFirstTraverser<T>impl<T> Iterator for AllocatingBreadthFirstTraverser<T> type Item = (FrozenNode<T>, usize);
pub fn allocating_breadth_first_traverse_stable(
&self,
start_depth: usize
) -> AllocatingBreadthFirstTraverser<T>ⓘNotable traits for AllocatingBreadthFirstTraverser<T>impl<T> Iterator for AllocatingBreadthFirstTraverser<T> type Item = (FrozenNode<T>, usize);
Returns the stable allocating breadth-first traverser.
The returned traverser will heap-allocate, and iterating all nodes is
O(n)
operation.
“Stable” here means that the hierarchy of the tree is currently frozen.
Stable traverser implements
DoubleEndedIterator
and can be
iterated backward.
Examples
use dendron::tree_node;
use dendron::traverse::DftEvent;
let frozen = tree_node! {
"root", [
/("0", [
/("0-0", ["0-0-0", "0-0-1"]),
"0-1",
/("0-2", ["0-2-0"]),
]),
/("1", [
"1-0",
]),
"2",
]
}
.bundle_new_hierarchy_edit_prohibition()
.expect("no hierarchy edit grant exist");
// root
// |-- 0
// | |-- 0-0
// | | |-- 0-0-0
// | | `-- 0-0-1
// | |-- 0-1
// | `-- 0-2
// | `-- 0-2-0
// |-- 1
// | `-- 1-0
// `-- 2
let depth2 = frozen
.allocating_breadth_first_traverse_stable(2)
.map(|(node, depth)| (*node.borrow_data(), depth))
.collect::<Vec<_>>();
assert_eq!(
depth2,
&[
("0-0", 2), ("0-1", 2), ("0-2", 2), ("1-0", 2),
("0-0-0", 3), ("0-0-1", 3), ("0-2-0", 3)
]
);
let all = frozen
.allocating_breadth_first_traverse_stable(0)
.map(|(node, depth)| (*node.borrow_data(), depth))
.collect::<Vec<_>>();
assert_eq!(
all,
&[
("root", 0),
("0", 1), ("1", 1), ("2", 1),
("0-0", 2), ("0-1", 2), ("0-2", 2), ("1-0", 2),
("0-0-0", 3), ("0-0-1", 3), ("0-2-0", 3)
]
);
sourceimpl<T> FrozenNode<T>
impl<T> FrozenNode<T>
Node creation and modification (to the other tree).
sourcepub fn try_clone_subtree(&self) -> Result<Node<T>, BorrowError> where
T: Clone,
pub fn try_clone_subtree(&self) -> Result<Node<T>, BorrowError> where
T: Clone,
Clones the subtree and returns it as a new independent tree.
Failures
Fails if any data associated to the node in the subtree is mutably (i.e. exclusively) borrowed.
See Node::try_clone_subtree
for usage examples.
sourcepub fn clone_subtree(&self) -> Node<T> where
T: Clone,
pub fn clone_subtree(&self) -> Node<T> where
T: Clone,
Clones the subtree and returns it as a new independent tree.
See Node::try_clone_subtree
for usage examples.
Panics
Panics if any data associated to the node in the subtree is mutably (i.e. exclusively) borrowed.
sourcepub fn try_clone_insert_subtree(
&self,
dest: InsertAs<&HotNode<T>>
) -> Result<HotNode<T>, HierarchyError> where
T: Clone,
pub fn try_clone_insert_subtree(
&self,
dest: InsertAs<&HotNode<T>>
) -> Result<HotNode<T>, HierarchyError> where
T: Clone,
Clones the node with its subtree, and inserts it to the given destination.
Returns the root node of the cloned new subtree.
Failures
Fails with BorrowNodeData
if any
data associated to the node in the subtree is mutably (i.e. exclusively)
borrowed.
See Node::try_clone_insert_subtree
for usage examples.
sourceimpl<T: Clone> FrozenNode<T>
impl<T: Clone> FrozenNode<T>
Serialization.
sourcepub fn to_events(&self) -> TreeSerializeIter<T>ⓘNotable traits for TreeSerializeIter<T>impl<T: Clone> Iterator for TreeSerializeIter<T> type Item = Result<Event<T>, BorrowError>;
pub fn to_events(&self) -> TreeSerializeIter<T>ⓘNotable traits for TreeSerializeIter<T>impl<T: Clone> Iterator for TreeSerializeIter<T> type Item = Result<Event<T>, BorrowError>;
Returns an iterator of serialized events for the subtree.
See Node::to_events
for usage examples.
sourceimpl<T> FrozenNode<T>
impl<T> FrozenNode<T>
Debug printing.
sourcepub fn debug_pretty_print(&self) -> DebugPrettyPrint<'_, T>
pub fn debug_pretty_print(&self) -> DebugPrettyPrint<'_, T>
Returns the pretty-printable proxy object to the node and descendants.
This is provided mainly for debugging purpose. Node that the output format is not guaranteed to be stable, and any format changes won’t be considered as breaking changes.
See Node::debug_pretty_print
for usage and example output.
sourcepub fn debug_print_local(&self) -> DebugPrintNodeLocal<'_, T>
pub fn debug_print_local(&self) -> DebugPrintNodeLocal<'_, T>
Returns a debug-printable proxy that does not dump neighbor nodes.
This is provided mainly for debugging purpose. Node that the output format is not guaranteed to be stable, and any format changes won’t be considered as breaking changes.
See Node::debug_print_local
for usage.
sourcepub fn debug_print_subtree(&self) -> DebugPrintSubtree<'_, T>
pub fn debug_print_subtree(&self) -> DebugPrintSubtree<'_, T>
Returns a debug-printable proxy that also dumps descendants recursively.
This is provided mainly for debugging purpose. Node that the output format is not guaranteed to be stable, and any format changes won’t be considered as breaking changes.
See Node::debug_print_subtree
for usage.
Trait Implementations
sourceimpl<T> Clone for FrozenNode<T>
impl<T> Clone for FrozenNode<T>
sourceimpl<T: Debug> Debug for FrozenNode<T>
impl<T: Debug> Debug for FrozenNode<T>
sourceimpl<T> From<FrozenNode<T>> for Node<T>
impl<T> From<FrozenNode<T>> for Node<T>
sourcefn from(node: FrozenNode<T>) -> Self
fn from(node: FrozenNode<T>) -> Self
Converts to this type from the input type.
sourceimpl<T, U: PartialEq<U>> PartialEq<&'_ FrozenNode<U>> for Node<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<&'_ FrozenNode<U>> for Node<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &&FrozenNode<U>) -> bool
fn eq(&self, other: &&FrozenNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<&'_ FrozenNode<U>> for HotNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<&'_ FrozenNode<U>> for HotNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &&FrozenNode<U>) -> bool
fn eq(&self, other: &&FrozenNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<&'_ HotNode<U>> for FrozenNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<&'_ HotNode<U>> for FrozenNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &&HotNode<U>) -> bool
fn eq(&self, other: &&HotNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<&'_ Node<U>> for FrozenNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<&'_ Node<U>> for FrozenNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &&Node<U>) -> bool
fn eq(&self, other: &&Node<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for FrozenNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for FrozenNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &FrozenNode<U>) -> bool
fn eq(&self, other: &FrozenNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
and plain
method.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for Node<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for Node<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &FrozenNode<U>) -> bool
fn eq(&self, other: &FrozenNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for &Node<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for &Node<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &FrozenNode<U>) -> bool
fn eq(&self, other: &FrozenNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for HotNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for HotNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &FrozenNode<U>) -> bool
fn eq(&self, other: &FrozenNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for &HotNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<FrozenNode<U>> for &HotNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &FrozenNode<U>) -> bool
fn eq(&self, other: &FrozenNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<HotNode<U>> for FrozenNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<HotNode<U>> for FrozenNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &HotNode<U>) -> bool
fn eq(&self, other: &HotNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<HotNode<U>> for &FrozenNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<HotNode<U>> for &FrozenNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &HotNode<U>) -> bool
fn eq(&self, other: &HotNode<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<Node<U>> for FrozenNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<Node<U>> for FrozenNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &Node<U>) -> bool
fn eq(&self, other: &Node<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
sourceimpl<T, U: PartialEq<U>> PartialEq<Node<U>> for &FrozenNode<T> where
T: PartialEq<U>,
impl<T, U: PartialEq<U>> PartialEq<Node<U>> for &FrozenNode<T> where
T: PartialEq<U>,
sourcefn eq(&self, other: &Node<U>) -> bool
fn eq(&self, other: &Node<U>) -> bool
Compares two subtrees.
Returns Ok(true)
if the two subtree are equal, even if they are stored
in different allocation.
Panics
May panic if associated data of some nodes are already borrowed exclusively (i.e. mutably).
To avoid panicking, use Node::try_eq
, FrozenNode::plain
, and
HotNode::plain
methods.
Examples
See the documentation for Node::try_eq
method.
impl<T: Eq> Eq for FrozenNode<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for FrozenNode<T>
impl<T> !Send for FrozenNode<T>
impl<T> !Sync for FrozenNode<T>
impl<T> Unpin for FrozenNode<T>
impl<T> !UnwindSafe for FrozenNode<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more