pub struct RedNode<'a, L: Language> {
pub green: &'a GreenNode<'a, L>,
pub offset: usize,
}Expand description
A red node that wraps a green node with absolute offset information.
Red nodes are position-aware views into the immutable green tree structure. They are small, copyable handles that can be used for traversal and analysis.
§Design Note: Reference vs Owned
We store &'a GreenNode<'a, L> here instead of GreenNode<'a, L> to keep
RedNode as small as possible (16 bytes: 8 for pointer + 8 for offset).
This makes it efficient to pass RedNode by value during tree traversal.
Fields§
§green: &'a GreenNode<'a, L>The underlying green node that contains the structural information.
offset: usizeThe absolute byte offset of this node in the source text.
Implementations§
Source§impl<'a, L: Language> RedNode<'a, L>
impl<'a, L: Language> RedNode<'a, L>
Sourcepub fn text<'s, S: Source + ?Sized>(&self, source: &'s S) -> Cow<'s, str>
pub fn text<'s, S: Source + ?Sized>(&self, source: &'s S) -> Cow<'s, str>
Returns the text content of this red node from the source.
Sourcepub fn new(green: &'a GreenNode<'a, L>, offset: usize) -> Self
pub fn new(green: &'a GreenNode<'a, L>, offset: usize) -> Self
Creates a new red node from a green node and absolute offset.
Sourcepub fn element_type(&self) -> L::ElementType
pub fn element_type(&self) -> L::ElementType
Returns the element type of this red node.
Sourcepub fn kind<T>(&self) -> Twhere
T: From<L::ElementType>,
pub fn kind<T>(&self) -> Twhere
T: From<L::ElementType>,
Returns the kind of this red node.
Sourcepub fn children(&self) -> RedChildren<'a, L> ⓘ
pub fn children(&self) -> RedChildren<'a, L> ⓘ
Returns an iterator over the child elements of this red node.
Sourcepub fn child_index_at_offset(&self, offset: usize) -> Option<usize>
pub fn child_index_at_offset(&self, offset: usize) -> Option<usize>
Finds the index of the child element containing the specified absolute byte offset.
§Arguments
offset- The absolute byte offset to search for.
Sourcepub fn child_at_offset(&self, offset: usize) -> Option<RedTree<'a, L>>
pub fn child_at_offset(&self, offset: usize) -> Option<RedTree<'a, L>>
Finds the child element containing the specified absolute byte offset.
§Arguments
offset- The absolute byte offset to search for.
Sourcepub fn leaf_at_offset(&self, offset: usize) -> Option<RedLeaf<L>>
pub fn leaf_at_offset(&self, offset: usize) -> Option<RedLeaf<L>>
Finds the leaf element at the specified absolute byte offset by traversing down the tree.
This method performs a deep search, following child nodes until a leaf is found.
§Arguments
offset- The absolute byte offset to search for.
Sourcepub fn first_token(&self) -> Option<RedLeaf<L>>
pub fn first_token(&self) -> Option<RedLeaf<L>>
Returns the first child token if any.