Struct ryml::Tree

source · []
pub struct Tree<'a> { /* private fields */ }
Expand description

Represents a parsed YAML tree

Implementations

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.

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.

Emit tree as YAML to an owned string.

Emit tree as JSON to an owned string.

Emit tree as YAML to the given buffer. Returns the number of bytes written.

Emit tree as JSON to the given buffer. Returns the number of bytes written.

Emit tree as YAML to the given writer. Returns the number of bytes written.

Emit tree as JSON to the given writer. Returns the number of bytes written.

Get the node to the root node.

Get a NodeRef to the root node.

Get a mutable NodeRef to the root node.

Get a NodeRef to the given node, if it exists.

Get a mutable NodeRef to the given node, if it exists.

Get the total number of nodes.

Returns true if the tree is empty.

Get the capacity of the tree.

Get the unused capacity of the tree.

Get the size of the internal string arena.

Returns true is the internal string arena is empty.

Get the capacity of the internal string arena.

Get the unused capacity of the internal string arena.

Reserves capacity to hold at least capacity nodes.

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.

Clear the tree and zero every node.

Note: Does not clear the arena. See also clear_arena.

Clear the internal string arena.

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.

Get the type of the given node, if it exists.

Get the type name of the given node, if it exists.

Get the text of the given node, if it exists and is a key.

Get the text of the tag on the key of the given node, if it exists and is a tagged key.

Get the text of the reference on the key of the given node, if it exists and is a reference.

Get the text of the anchor on the key of the given node, if it exists and is an anchor.

Get the whole scalar key of the given node, if it exists and is a scalar key.

Get the text of the given node, if it exists and is a value.

Get the text of the tag on the value of the given node, if it exists and is a tagged value.

Get the text of the reference on the value of the given node, if it exists and is a reference.

Get the text of the anchor on the value of the given node, if it exists and is an anchor.

Get the whole scalar value of the given node, if it exists and is a scalar value.

If the given node exists, returns true if it is a root.

If the given node exists, returns true if it is a stream.

If the given node exists, returns true if it is a doc.

If the given node exists, returns true if it is a container.

If the given node exists, returns true if it is a map.

If the given node exists, returns true if it is a seq.

If the given node exists, returns true if it has a value.

If the given node exists, returns true if it has a key.

If the given node exists, returns true if it is a value.

If the given node exists, returns true if it is a keyval.

If the given node exists, returns true if it has a tagged key.

If the given node exists, returns true if it has a tagged value.

If the given node exists, returns true if it has an anchor key.

If the given node exists, returns true if it has an anchor value.

If the given node exists, returns true if it is a key_ref.

If the given node exists, returns true if it is a val_ref.

If the given node exists, returns true if it is a ref.

If the given node exists, returns true if it is a anchor_or_ref.

If the given node exists, returns true if it is a key_quoted.

If the given node exists, returns true if it is a val_quoted.

If the given node exists, returns true if it is a quoted.

If the given node exists, returns true if it is a anchor.

If the given node exists, returns true if the parent is a sequence.

If the given node exists, returns true if the parent is a map.

If the given node exists, returns true if it is empty.

If the given node exists, returns true if it has an anchor.

If the given node exists, returns true if it has a parent.

If the given node exists, returns true if it has a child.

If the given node exists, returns true if it has children.

If the given node exists, returns true if it has a sibling.

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.

If the given node exists and has a parent, returns the parent node.

If the given node exists and has a previous sibling, returns the index to the sibling node.

If the given node exists and has a next sibling, returns the index to the sibling node.

If the given node exists and has children, returns the number of children.

If the given node exists and has the given child, returns the position of the child in the parent node.

If the given node exists and has children, returns the index of the first child node.

If the given node exists and has children, returns the index to the last child node.

If the given node exists and has a child at the given position, returns the index to the child node.

If the given node exists and has a child at the given key, returns the index to the child node.

If the given node exists and has siblings, returns the number of siblings.

If the given node exists and has other siblings, returns the number of other siblings.

If the given node exists and has the given sibling, get position of the sibling in in the parent.

If the given node exists and has siblings, returns the index to the first sibling node.

If the given node exists and has siblings, returns the index to the last sibling node.

If the given node exists and has a sibling as the given position, returns the index to the sibling node.

If the given node exists and has a sibling at the given key, returns the index to the sibling node.

Turn the given node into a key-value pair.

Turn the given node into a key-value pair with additional flags.

Turn the given node with the given key into a map.

Turn the given node with the given key into a map with additional flags.

Turn the given node with the given key into a sequence.

Turn the given node with the given key into a sequence with additional flags.

Turn the given node into a value.

Turn the given node into a value with additional flags.

Turn the given node into a stream.

Turn the given node into a stream with additional flags.

Turn the given node into a map.

Turn the given node into a map with additional flags.

Turn the given node into a sequence.

Turn the given node into a sequence with additional flags.

Turn the given node into a doc.

Turn the given node into a doc with additional flags.

Set the tag on the key of the given node.

Set the anchor on the key of the given node.

Set the anchor on the value of the given node.

Set the ref on the key of the given node.

Set the ref on the value of the given node.

Set the tag on the value of the given node.

Remove the anchor on the key of the given node.

Remove the anchor on the value of the given node.

Remove the reference on the key of the given node.

Remove the reference on the value of the given node.

Remove the reference on the anchor of the given node.

Insert a new node as the child of the given parent at the given position, returning its index.

Insert a new node as the first child of the given parent, returning its index.

Insert a new node as the last child of the given parent, returning its index.

Insert a new node as the sibling of the given node, returning its index.

Insert a new node as the first sibling of the given node, returning its index.

Insert a new node as the last sibling of the given node, returning its index.

Remove the given node from its parent, including any children.

Remove all children from a given node, leaving the node itself.

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.

Change the type of a node, resetting its contents if necessary and returning whether the change was possible.

Recursively duplicate the given node, returning the index to the duplicate.

Recursively duplicate the given node from a different tree, returning the index to the duplicate.

Recursively duplicate the children of the given node (but not the node itself), returning the index of the last duplicated child.

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.

Duplicate the contents of a given node to the given index.

Duplicate the contents of a given node from another tree to the given index.

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.

Change the node’s position in the parent.

Change the node’s parent and position.

Change the node’s parent (in a different tree) and position, returning the new index.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

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

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.