#[repr(transparent)]
pub struct Node<'a>(_, _);
Expand description

A single node within a syntax Tree.

Implementations

Get a numeric id for this node that is unique.

Within a given syntax tree, no two nodes have the same id. However, if a new tree is created based on an older tree, and a node from the old tree is reused in the process, then that node will have the same id in both trees.

Get this node’s type as a numerical id.

Get this node’s type as a string.

Get the Language that was used to parse this node’s syntax tree.

Check if this node is named.

Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.

Check if this node is extra.

Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere.

Check if this node has been edited.

Check if this node represents a syntax error or contains any syntax errors anywhere within it.

Check if this node represents a syntax error.

Syntax errors represent parts of the code that could not be incorporated into a valid syntax tree.

Check if this node is missing.

Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.

Get the byte offsets where this node starts.

Get the byte offsets where this node end.

Get the byte range of source code that this node represents.

Get the range of source code that this node represents, both in terms of raw bytes and of row/column coordinates.

Get this node’s start position in terms of rows and columns.

Get this node’s end position in terms of rows and columns.

Get the node’s child at the given index, where zero represents the first child.

This method is fairly fast, but its cost is technically log(i), so you if you might be iterating over a long list of children, you should use Node::children instead.

Get this node’s number of children.

Get this node’s named child at the given index.

See also Node::is_named. This method is fairly fast, but its cost is technically log(i), so you if you might be iterating over a long list of children, you should use Node::named_children instead.

Get this node’s number of named children.

See also Node::is_named.

Get the first child with the given field name.

If multiple children may have the same field name, access them using children_by_field_name

Get this node’s child with the given numerical field id.

See also child_by_field_name. You can convert a field name to an id using Language::field_id_for_name.

Get the field name of this node’s child at the given index.

Iterate over this node’s children.

A TreeCursor is used to retrieve the children efficiently. Obtain a TreeCursor by calling Tree::walk or Node::walk. To avoid unnecessary allocations, you should reuse the same cursor for subsequent calls to this method.

If you’re walking the tree recursively, you may want to use the TreeCursor APIs directly instead.

Iterate over this node’s named children.

See also Node::children.

Iterate over this node’s children with a given field name.

See also Node::children.

Iterate over this node’s children with a given field id.

See also Node::children_by_field_name.

Get this node’s immediate parent.

Get this node’s next sibling.

Get this node’s previous sibling.

Get this node’s next named sibling.

Get this node’s previous named sibling.

Get the smallest node within this node that spans the given range.

Get the smallest named node within this node that spans the given range.

Get the smallest node within this node that spans the given range.

Get the smallest named node within this node that spans the given range.

Create a new TreeCursor starting from this node.

Edit this node to keep it in-sync with source code that has been edited.

This function is only rarely needed. When you edit a syntax tree with the Tree::edit method, all of the nodes that you retrieve from the tree afterward will already reflect the edit. You only need to use Node::edit when you have a specific Node instance that you want to keep and continue to use after an edit.

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

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. 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

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