pub struct Tree<'a> { /* private fields */ }Expand description
Represents a parsed YAML tree
Implementations
sourceimpl<'a> Tree<'a>
impl<'a> Tree<'a>
sourcepub fn parse(text: impl AsRef<str>) -> Result<Tree<'a>, Error>
pub fn parse(text: impl AsRef<str>) -> Result<Tree<'a>, Error>
Create a new tree and parse into its root.
The immutable YAML source is first copied to the tree’s arena, and
parsed from there.
sourcepub fn parse_in_place(text: impl AsMut<str> + 'a) -> Result<Tree<'a>, Error>
pub fn parse_in_place(text: impl AsMut<str> + 'a) -> Result<Tree<'a>, Error>
Create a new tree and parse into its root.
A mutable reference to the YAML source is passed to the tree parser,
and parsed in-situ.
sourcepub fn emit_to_buffer(&self, buf: &mut [u8]) -> Result<usize, Error>
pub fn emit_to_buffer(&self, buf: &mut [u8]) -> Result<usize, Error>
Emit tree as YAML to the given buffer. Returns the number of bytes written.
sourcepub fn emit_json_to_buffer(&self, buf: &mut [u8]) -> Result<usize, Error>
pub fn emit_json_to_buffer(&self, buf: &mut [u8]) -> Result<usize, Error>
Emit tree as JSON to the given buffer. Returns the number of bytes written.
sourcepub fn emit_to_writer<W: Write + Seek>(
&self,
writer: &mut W
) -> Result<usize, Error>
pub fn emit_to_writer<W: Write + Seek>(
&self,
writer: &mut W
) -> Result<usize, Error>
Emit tree as YAML to the given writer. Returns the number of bytes written.
sourcepub fn emit_json_to_writer<W: Write + Seek>(
&self,
writer: &mut W
) -> Result<usize, Error>
pub fn emit_json_to_writer<W: Write + Seek>(
&self,
writer: &mut W
) -> Result<usize, Error>
Emit tree as JSON to the given writer. Returns the number of bytes written.
sourcepub fn root_ref<'t>(&'t self) -> Result<NodeRef<'a, 't, '_, &'t Self>, Error>
pub fn root_ref<'t>(&'t self) -> Result<NodeRef<'a, 't, '_, &'t Self>, Error>
Get a NodeRef to the root node.
sourcepub fn root_ref_mut<'t>(
&'t mut self
) -> Result<NodeRef<'a, 't, '_, &'t mut Tree<'a>>, Error>
pub fn root_ref_mut<'t>(
&'t mut self
) -> Result<NodeRef<'a, 't, '_, &'t mut Tree<'a>>, Error>
Get a mutable NodeRef to the root node.
sourcepub fn get<'t>(
&'t self,
index: usize
) -> Result<NodeRef<'a, 't, '_, &'t Self>, Error>
pub fn get<'t>(
&'t self,
index: usize
) -> Result<NodeRef<'a, 't, '_, &'t Self>, Error>
Get a NodeRef to the given node, if it exists.
sourcepub fn get_mut<'t>(
&'t mut self,
index: usize
) -> Result<NodeRef<'a, 't, '_, &'t mut Self>, Error>
pub fn get_mut<'t>(
&'t mut self,
index: usize
) -> Result<NodeRef<'a, 't, '_, &'t mut Self>, Error>
Get a mutable NodeRef to the given node, if it exists.
sourcepub fn arena_is_empty(&self) -> bool
pub fn arena_is_empty(&self) -> bool
Returns true is the internal string arena is empty.
sourcepub fn arena_capacity(&self) -> usize
pub fn arena_capacity(&self) -> usize
Get the capacity of the internal string arena.
sourcepub fn arena_slack(&self) -> Result<usize, Error>
pub fn arena_slack(&self) -> Result<usize, Error>
Get the unused capacity of the internal string arena.
sourcepub fn reserve(&mut self, node_capacity: usize)
pub fn reserve(&mut self, node_capacity: usize)
Reserves capacity to hold at least capacity nodes.
sourcepub fn reserve_arena(&mut self, arena_capacity: usize)
pub fn reserve_arena(&mut self, arena_capacity: usize)
Ensures the tree’s internal string arena is at least the given capacity.
Note: Growing the arena may cause relocation of the entire existing arena, and thus change the contents of individual nodes.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the tree and zero every node.
Note: Does not clear the arena.
See also clear_arena.
sourcepub fn clear_arena(&mut self)
pub fn clear_arena(&mut self)
Clear the internal string arena.
sourcepub fn resolve(&mut self) -> Result<(), Error>
pub fn resolve(&mut self) -> Result<(), Error>
Resolve references (aliases <- anchors) in the tree.
Dereferencing is opt-in; after parsing,
Tree::resolve() has to be called explicitly for
obtaining resolved references in the tree. This method will resolve
all references and substitute the anchored values in place of the
reference.
This method first does a full traversal of the tree to gather all anchors and references in a separate collection, then it goes through that collection to locate the names, which it does by obeying the YAML standard diktat that “an alias node refers to the most recent node in the serialization having the specified anchor”
So, depending on the number of anchor/alias nodes, thit is a potentially expensive operation, with a best-case linear complexity (from the initial traversal). This potential cost is the reason for requiring an explicit call.
sourcepub fn node_type(&self, node: usize) -> Result<NodeType, Error>
pub fn node_type(&self, node: usize) -> Result<NodeType, Error>
Get the type of the given node, if it exists.
sourcepub fn node_type_as_str(&self, node: usize) -> Result<&str, Error>
pub fn node_type_as_str(&self, node: usize) -> Result<&str, Error>
Get the type name of the given node, if it exists.
sourcepub fn key(&self, node: usize) -> Result<&str, Error>
pub fn key(&self, node: usize) -> Result<&str, Error>
Get the text of the given node, if it exists and is a key.
sourcepub fn key_tag(&self, node: usize) -> Result<&str, Error>
pub fn key_tag(&self, node: usize) -> Result<&str, Error>
Get the text of the tag on the key of the given node, if it exists and is a tagged key.
sourcepub fn key_ref(&self, node: usize) -> Result<&str, Error>
pub fn key_ref(&self, node: usize) -> Result<&str, Error>
Get the text of the reference on the key of the given node, if it exists and is a reference.
sourcepub fn key_anchor(&self, node: usize) -> Result<&str, Error>
pub fn key_anchor(&self, node: usize) -> Result<&str, Error>
Get the text of the anchor on the key of the given node, if it exists and is an anchor.
sourcepub fn key_scalar(&self, node: usize) -> Result<&NodeScalar<'_>, Error>
pub fn key_scalar(&self, node: usize) -> Result<&NodeScalar<'_>, Error>
Get the whole scalar key of the given node, if it exists and is a scalar key.
sourcepub fn val(&self, node: usize) -> Result<&str, Error>
pub fn val(&self, node: usize) -> Result<&str, Error>
Get the text of the given node, if it exists and is a value.
sourcepub fn val_tag(&self, node: usize) -> Result<&str, Error>
pub fn val_tag(&self, node: usize) -> Result<&str, Error>
Get the text of the tag on the value of the given node, if it exists and is a tagged value.
sourcepub fn val_ref(&self, node: usize) -> Result<&str, Error>
pub fn val_ref(&self, node: usize) -> Result<&str, Error>
Get the text of the reference on the value of the given node, if it exists and is a reference.
sourcepub fn val_anchor(&self, node: usize) -> Result<&str, Error>
pub fn val_anchor(&self, node: usize) -> Result<&str, Error>
Get the text of the anchor on the value of the given node, if it exists and is an anchor.
sourcepub fn val_scalar(&self, node: usize) -> Result<&NodeScalar<'_>, Error>
pub fn val_scalar(&self, node: usize) -> Result<&NodeScalar<'_>, Error>
Get the whole scalar value of the given node, if it exists and is a scalar value.
sourcepub fn is_root(&self, node: usize) -> Result<bool, Error>
pub fn is_root(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a root.
sourcepub fn is_stream(&self, node: usize) -> Result<bool, Error>
pub fn is_stream(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a stream.
sourcepub fn is_doc(&self, node: usize) -> Result<bool, Error>
pub fn is_doc(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a doc.
sourcepub fn is_container(&self, node: usize) -> Result<bool, Error>
pub fn is_container(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a container.
sourcepub fn is_map(&self, node: usize) -> Result<bool, Error>
pub fn is_map(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a map.
sourcepub fn is_seq(&self, node: usize) -> Result<bool, Error>
pub fn is_seq(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a seq.
sourcepub fn has_val(&self, node: usize) -> Result<bool, Error>
pub fn has_val(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has a value.
sourcepub fn has_key(&self, node: usize) -> Result<bool, Error>
pub fn has_key(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has a key.
sourcepub fn is_val(&self, node: usize) -> Result<bool, Error>
pub fn is_val(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a value.
sourcepub fn is_keyval(&self, node: usize) -> Result<bool, Error>
pub fn is_keyval(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a keyval.
sourcepub fn has_key_tag(&self, node: usize) -> Result<bool, Error>
pub fn has_key_tag(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has a tagged key.
sourcepub fn has_val_tag(&self, node: usize) -> Result<bool, Error>
pub fn has_val_tag(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has a tagged value.
sourcepub fn has_key_anchor(&self, node: usize) -> Result<bool, Error>
pub fn has_key_anchor(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has an anchor key.
sourcepub fn has_val_anchor(&self, node: usize) -> Result<bool, Error>
pub fn has_val_anchor(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has an anchor value.
sourcepub fn is_key_ref(&self, node: usize) -> Result<bool, Error>
pub fn is_key_ref(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a key_ref.
sourcepub fn is_val_ref(&self, node: usize) -> Result<bool, Error>
pub fn is_val_ref(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a val_ref.
sourcepub fn is_ref(&self, node: usize) -> Result<bool, Error>
pub fn is_ref(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a ref.
sourcepub fn is_anchor_or_ref(&self, node: usize) -> Result<bool, Error>
pub fn is_anchor_or_ref(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a anchor_or_ref.
sourcepub fn is_key_quoted(&self, node: usize) -> Result<bool, Error>
pub fn is_key_quoted(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a key_quoted.
sourcepub fn is_val_quoted(&self, node: usize) -> Result<bool, Error>
pub fn is_val_quoted(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a val_quoted.
sourcepub fn is_quoted(&self, node: usize) -> Result<bool, Error>
pub fn is_quoted(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a quoted.
sourcepub fn is_anchor(&self, node: usize) -> Result<bool, Error>
pub fn is_anchor(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is a anchor.
sourcepub fn parent_is_seq(&self, node: usize) -> Result<bool, Error>
pub fn parent_is_seq(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if the parent is a sequence.
sourcepub fn parent_is_map(&self, node: usize) -> Result<bool, Error>
pub fn parent_is_map(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if the parent is a map.
sourcepub fn is_node_empty(&self, node: usize) -> Result<bool, Error>
pub fn is_node_empty(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it is empty.
sourcepub fn has_anchor(&self, node: usize, anchor: &str) -> Result<bool, Error>
pub fn has_anchor(&self, node: usize, anchor: &str) -> Result<bool, Error>
If the given node exists, returns true if it has an anchor.
sourcepub fn has_parent(&self, node: usize) -> Result<bool, Error>
pub fn has_parent(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has a parent.
sourcepub fn has_child(&self, node: usize, key: &str) -> Result<bool, Error>
pub fn has_child(&self, node: usize, key: &str) -> Result<bool, Error>
If the given node exists, returns true if it has a child.
sourcepub fn has_children(&self, node: usize) -> Result<bool, Error>
pub fn has_children(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has children.
sourcepub fn has_sibling(&self, node: usize, key: &str) -> Result<bool, Error>
pub fn has_sibling(&self, node: usize, key: &str) -> Result<bool, Error>
If the given node exists, returns true if it has a sibling.
sourcepub fn has_siblings(&self, node: usize) -> Result<bool, Error>
pub fn has_siblings(&self, node: usize) -> Result<bool, Error>
If the given node exists, returns true if it has siblings.
Note: This corresponds to has_other_siblings() in the C++ API, as
the plain has_siblings() function always returns true by counting the
node itself, which seems rather pointless and is not the obvious meaning
of a method by the name.
sourcepub fn parent(&self, node: usize) -> Result<usize, Error>
pub fn parent(&self, node: usize) -> Result<usize, Error>
If the given node exists and has a parent, returns the parent node.
sourcepub fn prev_sibling(&self, node: usize) -> Result<usize, Error>
pub fn prev_sibling(&self, node: usize) -> Result<usize, Error>
If the given node exists and has a previous sibling, returns the index to the sibling node.
sourcepub fn next_sibling(&self, node: usize) -> Result<usize, Error>
pub fn next_sibling(&self, node: usize) -> Result<usize, Error>
If the given node exists and has a next sibling, returns the index to the sibling node.
sourcepub fn num_children(&self, node: usize) -> Result<usize, Error>
pub fn num_children(&self, node: usize) -> Result<usize, Error>
If the given node exists and has children, returns the number of children.
sourcepub fn child_pos(&self, node: usize, child: usize) -> Result<usize, Error>
pub fn child_pos(&self, node: usize, child: usize) -> Result<usize, Error>
If the given node exists and has the given child, returns the position of the child in the parent node.
sourcepub fn first_child(&self, node: usize) -> Result<usize, Error>
pub fn first_child(&self, node: usize) -> Result<usize, Error>
If the given node exists and has children, returns the index of the first child node.
sourcepub fn last_child(&self, node: usize) -> Result<usize, Error>
pub fn last_child(&self, node: usize) -> Result<usize, Error>
If the given node exists and has children, returns the index to the last child node.
sourcepub fn child_at(&self, node: usize, pos: usize) -> Result<usize, Error>
pub fn child_at(&self, node: usize, pos: usize) -> Result<usize, Error>
If the given node exists and has a child at the given position, returns the index to the child node.
sourcepub fn find_child(&self, node: usize, key: &str) -> Result<usize, Error>
pub fn find_child(&self, node: usize, key: &str) -> Result<usize, Error>
If the given node exists and has a child at the given key, returns the index to the child node.
sourcepub fn num_siblings(&self, node: usize) -> Result<usize, Error>
pub fn num_siblings(&self, node: usize) -> Result<usize, Error>
If the given node exists and has siblings, returns the number of siblings.
sourcepub fn num_other_siblings(&self, node: usize) -> Result<usize, Error>
pub fn num_other_siblings(&self, node: usize) -> Result<usize, Error>
If the given node exists and has other siblings, returns the number of other siblings.
sourcepub fn sibling_pos(&self, node: usize, sibling: usize) -> Result<usize, Error>
pub fn sibling_pos(&self, node: usize, sibling: usize) -> Result<usize, Error>
If the given node exists and has the given sibling, get position of the sibling in in the parent.
sourcepub fn first_sibling(&self, node: usize) -> Result<usize, Error>
pub fn first_sibling(&self, node: usize) -> Result<usize, Error>
If the given node exists and has siblings, returns the index to the first sibling node.
sourcepub fn last_sibling(&self, node: usize) -> Result<usize, Error>
pub fn last_sibling(&self, node: usize) -> Result<usize, Error>
If the given node exists and has siblings, returns the index to the last sibling node.
sourcepub fn sibling_at(&self, node: usize, pos: usize) -> Result<usize, Error>
pub fn sibling_at(&self, node: usize, pos: usize) -> Result<usize, Error>
If the given node exists and has a sibling as the given position, returns the index to the sibling node.
sourcepub fn find_sibling(&self, node: usize, key: &str) -> Result<usize, Error>
pub fn find_sibling(&self, node: usize, key: &str) -> Result<usize, Error>
If the given node exists and has a sibling at the given key, returns the index to the sibling node.
sourcepub fn to_keyval(&mut self, node: usize, key: &str, val: &str) -> Result<(), Error>
pub fn to_keyval(&mut self, node: usize, key: &str, val: &str) -> Result<(), Error>
Turn the given node into a key-value pair.
sourcepub fn to_keyval_with_flags(
&mut self,
node: usize,
key: &str,
val: &str,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_keyval_with_flags(
&mut self,
node: usize,
key: &str,
val: &str,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node into a key-value pair with additional flags.
sourcepub fn to_map_by_key(&mut self, node: usize, key: &str) -> Result<(), Error>
pub fn to_map_by_key(&mut self, node: usize, key: &str) -> Result<(), Error>
Turn the given node with the given key into a map.
sourcepub fn to_map_with_key_and_flags(
&mut self,
node: usize,
key: &str,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_map_with_key_and_flags(
&mut self,
node: usize,
key: &str,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node with the given key into a map with additional flags.
sourcepub fn to_seq_by_key(&mut self, node: usize, key: &str) -> Result<(), Error>
pub fn to_seq_by_key(&mut self, node: usize, key: &str) -> Result<(), Error>
Turn the given node with the given key into a sequence.
sourcepub fn to_seq_with_key_and_flags(
&mut self,
node: usize,
key: &str,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_seq_with_key_and_flags(
&mut self,
node: usize,
key: &str,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node with the given key into a sequence with additional flags.
sourcepub fn to_val(&mut self, node: usize, val: &str) -> Result<(), Error>
pub fn to_val(&mut self, node: usize, val: &str) -> Result<(), Error>
Turn the given node into a value.
sourcepub fn to_val_with_flags(
&mut self,
node: usize,
val: &str,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_val_with_flags(
&mut self,
node: usize,
val: &str,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node into a value with additional flags.
sourcepub fn to_stream(&mut self, node: usize) -> Result<(), Error>
pub fn to_stream(&mut self, node: usize) -> Result<(), Error>
Turn the given node into a stream.
sourcepub fn to_stream_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_stream_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node into a stream with additional flags.
sourcepub fn to_map_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_map_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node into a map with additional flags.
sourcepub fn to_seq(&mut self, node: usize) -> Result<(), Error>
pub fn to_seq(&mut self, node: usize) -> Result<(), Error>
Turn the given node into a sequence.
sourcepub fn to_seq_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_seq_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node into a sequence with additional flags.
sourcepub fn to_doc_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
pub fn to_doc_with_flags(
&mut self,
node: usize,
more_flags: NodeType
) -> Result<(), Error>
Turn the given node into a doc with additional flags.
sourcepub fn set_key_tag(&mut self, node: usize, tag: &str) -> Result<(), Error>
pub fn set_key_tag(&mut self, node: usize, tag: &str) -> Result<(), Error>
Set the tag on the key of the given node.
sourcepub fn set_key_anchor(&mut self, node: usize, anchor: &str) -> Result<(), Error>
pub fn set_key_anchor(&mut self, node: usize, anchor: &str) -> Result<(), Error>
Set the anchor on the key of the given node.
sourcepub fn set_val_anchor(&mut self, node: usize, anchor: &str) -> Result<(), Error>
pub fn set_val_anchor(&mut self, node: usize, anchor: &str) -> Result<(), Error>
Set the anchor on the value of the given node.
sourcepub fn set_key_ref(&mut self, node: usize, refr: &str) -> Result<(), Error>
pub fn set_key_ref(&mut self, node: usize, refr: &str) -> Result<(), Error>
Set the ref on the key of the given node.
sourcepub fn set_val_ref(&mut self, node: usize, refr: &str) -> Result<(), Error>
pub fn set_val_ref(&mut self, node: usize, refr: &str) -> Result<(), Error>
Set the ref on the value of the given node.
sourcepub fn set_val_tag(&mut self, node: usize, tag: &str) -> Result<(), Error>
pub fn set_val_tag(&mut self, node: usize, tag: &str) -> Result<(), Error>
Set the tag on the value of the given node.
sourcepub fn rem_key_anchor(&mut self, node: usize) -> Result<(), Error>
pub fn rem_key_anchor(&mut self, node: usize) -> Result<(), Error>
Remove the anchor on the key of the given node.
sourcepub fn rem_val_anchor(&mut self, node: usize) -> Result<(), Error>
pub fn rem_val_anchor(&mut self, node: usize) -> Result<(), Error>
Remove the anchor on the value of the given node.
sourcepub fn rem_key_ref(&mut self, node: usize) -> Result<(), Error>
pub fn rem_key_ref(&mut self, node: usize) -> Result<(), Error>
Remove the reference on the key of the given node.
sourcepub fn rem_val_ref(&mut self, node: usize) -> Result<(), Error>
pub fn rem_val_ref(&mut self, node: usize) -> Result<(), Error>
Remove the reference on the value of the given node.
sourcepub fn rem_anchor_ref(&mut self, node: usize) -> Result<(), Error>
pub fn rem_anchor_ref(&mut self, node: usize) -> Result<(), Error>
Remove the reference on the anchor of the given node.
sourcepub fn insert_child(
&mut self,
parent: usize,
after: usize
) -> Result<usize, Error>
pub fn insert_child(
&mut self,
parent: usize,
after: usize
) -> Result<usize, Error>
Insert a new node as the child of the given parent at the given position, returning its index.
sourcepub fn prepend_child(&mut self, parent: usize) -> Result<usize, Error>
pub fn prepend_child(&mut self, parent: usize) -> Result<usize, Error>
Insert a new node as the first child of the given parent, returning its index.
sourcepub fn append_child(&mut self, parent: usize) -> Result<usize, Error>
pub fn append_child(&mut self, parent: usize) -> Result<usize, Error>
Insert a new node as the last child of the given parent, returning its index.
sourcepub fn insert_sibling(
&mut self,
node: usize,
after: usize
) -> Result<usize, Error>
pub fn insert_sibling(
&mut self,
node: usize,
after: usize
) -> Result<usize, Error>
Insert a new node as the sibling of the given node, returning its index.
sourcepub fn prepend_sibling(&mut self, node: usize) -> Result<usize, Error>
pub fn prepend_sibling(&mut self, node: usize) -> Result<usize, Error>
Insert a new node as the first sibling of the given node, returning its index.
sourcepub fn append_sibling(&mut self, node: usize) -> Result<usize, Error>
pub fn append_sibling(&mut self, node: usize) -> Result<usize, Error>
Insert a new node as the last sibling of the given node, returning its index.
sourcepub fn remove(&mut self, node: usize) -> Result<(), Error>
pub fn remove(&mut self, node: usize) -> Result<(), Error>
Remove the given node from its parent, including any children.
sourcepub fn remove_children(&mut self, node: usize) -> Result<(), Error>
pub fn remove_children(&mut self, node: usize) -> Result<(), Error>
Remove all children from a given node, leaving the node itself.
sourcepub fn reorder(&mut self) -> Result<(), Error>
pub fn reorder(&mut self) -> Result<(), Error>
Reorder the tree in memory so that all the nodes are stored in a linear sequence when visited in depth-first order. This will invalidate existing ids/indicies, since the node id is its position in the node array.
sourcepub fn change_type(
&mut self,
node: usize,
new_type: NodeType
) -> Result<bool, Error>
pub fn change_type(
&mut self,
node: usize,
new_type: NodeType
) -> Result<bool, Error>
Change the type of a node, resetting its contents if necessary and returning whether the change was possible.
sourcepub fn duplicate(
&mut self,
node: usize,
new_parent: usize,
after: usize
) -> Result<usize, Error>
pub fn duplicate(
&mut self,
node: usize,
new_parent: usize,
after: usize
) -> Result<usize, Error>
Recursively duplicate the given node, returning the index to the duplicate.
sourcepub fn duplicate_from_tree(
&mut self,
tree: &Self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
pub fn duplicate_from_tree(
&mut self,
tree: &Self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
Recursively duplicate the given node from a different tree, returning the index to the duplicate.
sourcepub fn duplicate_children(
&mut self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
pub fn duplicate_children(
&mut self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
Recursively duplicate the children of the given node (but not the node itself), returning the index of the last duplicated child.
sourcepub fn duplicate_children_from_tree(
&mut self,
tree: &Self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
pub fn duplicate_children_from_tree(
&mut self,
tree: &Self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
Recursively duplicate the children of the given node (but not the node itself) from a different tree, returning the index of the last duplicated child.
sourcepub fn duplicate_contents(
&mut self,
node: usize,
dest_index: usize
) -> Result<(), Error>
pub fn duplicate_contents(
&mut self,
node: usize,
dest_index: usize
) -> Result<(), Error>
Duplicate the contents of a given node to the given index.
sourcepub fn duplicate_contents_from_tree(
&mut self,
tree: &Self,
node: usize,
dest_index: usize
) -> Result<(), Error>
pub fn duplicate_contents_from_tree(
&mut self,
tree: &Self,
node: usize,
dest_index: usize
) -> Result<(), Error>
Duplicate the contents of a given node from another tree to the given index.
sourcepub fn duplicate_children_no_rep(
&mut self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
pub fn duplicate_children_no_rep(
&mut self,
node: usize,
parent: usize,
after: usize
) -> Result<usize, Error>
Duplicate the node’s children (but not the node) in a new parent, but omit repetitions where a duplicated node has the same key (in maps) or value (in sequences). If one of the duplicated children has the same key (in maps) or value (in sequences) as one of the parent’s children, the one that is placed closest to the end will prevail.
sourcepub fn move_node(&mut self, node: usize, after: usize) -> Result<(), Error>
pub fn move_node(&mut self, node: usize, after: usize) -> Result<(), Error>
Change the node’s position in the parent.
Trait Implementations
impl Eq for Tree<'_>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Tree<'a>
impl<'a> !Send for Tree<'a>
impl<'a> !Sync for Tree<'a>
impl<'a> !Unpin for Tree<'a>
impl<'a> !UnwindSafe for Tree<'a>
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