Struct dendron::node::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§

Creates a plain node reference for the node.

Examples
use dendron::{FrozenNode, Node};

let frozen = Node::new_tree("root")
    .bundle_new_hierarchy_edit_prohibition()
    .expect("no hierarchy edit grant exist");

let plain: Node<_> = frozen.plain();

Tree hierarchy edit prohibitions.

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();

Data access.

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"
);

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");

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");

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");

Returns true if the two FrozenNodes 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"
);

Neighbor nodes accessor.

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()));

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());

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()));

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));

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));

Returns the parent node.

See Node::parent for usage examples.

Returns the previous sibling.

See Node::prev_sibling for usage examples.

Returns the next sibling.

See Node::next_sibling for usage examples.

Returns the first sibling.

See Node::first_sibling for usage examples.

Returns the last sibling.

See Node::last_sibling for usage examples.

Returns the first and the last siblings.

See Node::first_last_sibling for usage examples.

Returns the first child node.

See Node::first_child for usage examples.

Returns the last child node.

See Node::last_child for usage examples.

Returns links to the first and the last child nodes.

See Node::first_last_child for usage examples.

Returns true if the previous sibling exists.

See Node::has_prev_sibling for usage examples.

Returns true if the next sibling exists.

See Node::has_prev_sibling for usage examples.

Returns true if the node has any children.

See Node::has_children for usage examples.

Returns the number of children.

This is O(1) operation.

See Node::num_children for usage examples.

👎Deprecated since 0.1.1: 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.

👎Deprecated since 0.1.1: 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.

👎Deprecated since 0.1.1: use HotNode::num_children

Returns the number of children.

Use num_children method instead.

See Node::count_children for usage examples.

Returns the number of preceding siblings.

Note that this is O(N) operation.

See Node::count_preceding_siblings for usage examples.

Returns the number of following siblings.

Note that this is O(N) operation.

See Node::count_following_siblings for usage examples.

Returns the number of ancestors.

Note that this is O(N) operation.

See Node::count_ancestors for usage examples.

Tree traverser.

Returns the depth-first traverser.

See Node::depth_first_traverse for usage examples.

Returns the reverse depth-first traverser.

See Node::depth_first_reverse_traverse for usage examples.

Returns the children traverser.

See Node::children for usage examples.

Returns the reverse children traverser.

See Node::children_reverse for usage examples.

Returns the ancestors traverser.

See Node::ancestors for usage examples.

Returns the ancestors traverser.

See Node::ancestors_or_self for usage examples.

Returns the siblings traverser.

See Node::siblings for usage examples.

Returns the reverse siblings traverser.

See Node::siblings_reverse for usage examples.

Returns the preceding siblings traverser.

See Node::preceding_siblings_or_self_reverse for usage examples.

Returns the preceding siblings traverser.

See Node::preceding_siblings_reverse for usage examples.

Returns the following siblings traverser.

See Node::following_siblings_or_self for usage examples.

Returns the following siblings traverser.

See Node::following_siblings for usage examples.

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.

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.

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.

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.

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.

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.

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.

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);

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)
    ]
);

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)
    ]
);

Node creation and modification (to the other tree).

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.

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.

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.

Serialization.

Returns an iterator of serialized events for the subtree.

See Node::to_events for usage examples.

Debug printing.

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.

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.

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Converts to this type from the input type.

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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.

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.