pub struct HotNode<T> { /* private fields */ }
Expand description

A Node with a tree hierarchy edit grant bundled.

HotNode can be created by Node::bundle_hierarchy_edit_grant or Node::bundle_new_hierarchy_edit_grant.

Panics

Panics if the number of active edit grants through this node is usize::MAX. This is very unlikely to happen without leaking grants.

Implementations

Creates a plain node reference for the node.

Examples
use dendron::{HotNode, Node};

let hot = HotNode::new_tree("root");
let plain: Node<_> = hot.plain();

Tree hierarchy edit grants.

Returns a copy of the tree hierarchy edit grant.

Examples
use dendron::HotNode;

let hot = HotNode::new_tree("root");
let grant = hot.extract_hierarchy_edit_grant();

Data access.

Returns a reference to the data associated to the node.

Examples
use dendron::HotNode;

let hot = HotNode::new_tree("root");
assert_eq!(
    *hot
        .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::HotNode;

let hot = HotNode::new_tree("root");
assert_eq!(*hot.borrow_data(), "root");

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

Examples
use dendron::HotNode;

let hot = HotNode::new_tree("root");

*hot.try_borrow_data_mut()
    .expect("should not fail since not borrowed from other place")
    = "ROOT";
assert_eq!(*hot.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::HotNode;

let hot = HotNode::new_tree("root");

*hot.borrow_data_mut() = "ROOT";
assert_eq!(*hot.borrow_data(), "ROOT");

Returns true if the two HotNodes point to the same allocation.

Examples
use dendron::HotNode;

let hot1 = HotNode::new_tree("root");
let hot2 = HotNode::new_tree("root");

assert!(hot1.ptr_eq(&hot1));

assert!(hot1 == hot2, "same content and hierarchy");
assert!(
    !hot1.ptr_eq(&hot2),
    "same content and hierarchy but different allocation"
);

Returns true if self and the given Node point to the same allocation.

Examples
use dendron::HotNode;

let hot = HotNode::new_tree("root");
assert!(hot.ptr_eq_plain(&hot.plain()));

Neighbor nodes accessor.

Returns the tree the node belongs to.

Examples
use dendron::HotNode;

let hot = HotNode::new_tree("root");
let tree = hot.tree();

assert!(tree.root().ptr_eq(&hot.plain()));

Returns true if the node is the root.

Examples
use dendron::HotNode;

let root = HotNode::new_tree("root");
let child = root.create_as_last_child("child");
//  root
//  `-- child

assert!(root.is_root());
assert!(!child.is_root());

Returns true if the given node belong to the same tree.

Examples
use dendron::HotNode;

let root = HotNode::new_tree("root");
let child = root.create_as_last_child("child");
//  root
//  `-- child

let other_node = HotNode::new_tree("other");

assert!(root.belongs_to_same_tree(&child));
assert!(child.belongs_to_same_tree(&root));

assert!(!root.belongs_to_same_tree(&other_node));

Returns the hot root node.

Examples
use dendron::HotNode;

let node = HotNode::new_tree("root");
let tree = node.tree();

assert!(tree.root().ptr_eq(&node.plain()));

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_next_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.

Node creation and hierarchy modification.

Creates and returns a new hot node as the root of a new tree.

Examples
use dendron::HotNode;

let root = HotNode::new_tree("root");

Detaches the node and its descendant from the current tree, and let it be another tree.

See Node::detach_subtree for usage examples.

Creates a node as the next sibling of self, and returns the new node.

See Node::try_create_node_as for usage examples.

Creates a node as the next sibling of self, and returns the new node.

See Node::create_node_as for usage examples.

Panics

Panics if the creation of a node at the specified position will make the tree hierarchy invalid.

Creates a node as the first child of self.

See Node::create_as_first_child for usage examples.

Creates a node as the last child of self.

See Node::create_as_last_child for usage examples.

Creates a node as the previous sibling of self.

See Node::try_create_as_prev_sibling for usage examples.

Failures

Returns HierarchyError::SiblingsWithoutParent as an error if self is a root node.

Creates a node as the previous sibling of self.

See Node::try_create_as_prev_sibling for usage examples.

Panics

Panics if self is a root node.

Creates a node as the next sibling of self.

See Node::try_create_as_next_sibling for usage examples.

Failures

Returns HierarchyError::SiblingsWithoutParent as an error if self is a root node.

Creates a node as the next sibling of self.

See Node::try_create_as_next_sibling for usage examples.

Failures

Returns HierarchyError::SiblingsWithoutParent as an error if self is a root node.

Inserts the children at the position of the node, and detach the node.

self will become the root of a new single-node tree.

Before:

parent
|-- prev
|-- self
|   |-- child0
|   |   `-- grandchild0-0
|   `-- child1
`-- next

After self.try_replace_with_children():

parent
|-- prev
|-- child0
|   `-- grandchild0-0
|-- child1
`-- next

self (detached)

See Node::try_replace_with_children for usage examples.

Failures

Fails if:

Inserts the children at the position of the node, and detach the node.

self will become the root of a new single-node tree.

See try_replace_with_children method.

Panics

Panics if:

  • the node is the root and has multiple children, or
  • the node is the root and has no children.

Clones the subtree and returns it as a new independent tree.

See Node::try_clone_subtree for usage examples.

Failures

Fails if any data associated to the node in the subtree is mutably (i.e. exclusively) borrowed.

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.

See Node::try_clone_insert_subtree for usage examples.

Failures

Fails if:

  • the hierarchy to be created is invalid, or
  • 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.

See try_clone_insert_subtree for detail.

Panics

Panics if:

  • the hierarchy to be created is invalid, or
  • any data associated to the node in the subtree is mutably (i.e. exclusively) borrowed.

Detaches the node with its subtree, and inserts it to the given destination.

Returns the root node of the transplanted subtree.

See Node::try_detach_insert_subtree for usage examples.

Detaches the node with its subtree, and inserts it to the given destination.

See Node::try_detach_insert_subtree for detail.

Panics

Panics if:

  • the hierarchy edit grant is not valid for the given node, or
  • the node (being moved) is an ancestor of the destination.

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

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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 !=.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.