pub struct SyntaxNodePtr<L: Language> { /* private fields */ }Expand description
A “pointer” to a SyntaxNode, via location in the source code.
Implementations§
Source§impl<L: Language> SyntaxNodePtr<L>
impl<L: Language> SyntaxNodePtr<L>
Sourcepub fn new(node: &SyntaxNode<L>) -> Self
pub fn new(node: &SyntaxNode<L>) -> Self
Returns a SyntaxNodePtr for the node.
Sourcepub fn to_node(&self, root: &SyntaxNode<L>) -> SyntaxNode<L>
pub fn to_node(&self, root: &SyntaxNode<L>) -> SyntaxNode<L>
Like Self::try_to_node but panics instead of returning None on
failure.
Sourcepub fn try_to_node(&self, root: &SyntaxNode<L>) -> Option<SyntaxNode<L>>
pub fn try_to_node(&self, root: &SyntaxNode<L>) -> Option<SyntaxNode<L>>
“Dereferences” the pointer to get the SyntaxNode it points to.
Returns None if the node is not found, so make sure that the root
syntax tree is equivalent to (i.e. is build from the same text from) the
tree which was originally used to get this SyntaxNodePtr.
Also returns None if root is not actually a root (i.e. it has a
parent).
The complexity is linear in the depth of the tree and logarithmic in
tree width. As most trees are shallow, thinking about this as
O(log(N)) in the size of the tree is not too wrong!
Sourcepub fn cast<N: AstNode<Language = L>>(self) -> Option<AstPtr<N>>
pub fn cast<N: AstNode<Language = L>>(self) -> Option<AstPtr<N>>
Casts this to an AstPtr to the given node type if possible.
Sourcepub fn text_range(&self) -> TextRange
pub fn text_range(&self) -> TextRange
Returns the range of the syntax node this points to.
Trait Implementations§
Source§impl<L: Clone + Language> Clone for SyntaxNodePtr<L>
impl<L: Clone + Language> Clone for SyntaxNodePtr<L>
Source§fn clone(&self) -> SyntaxNodePtr<L>
fn clone(&self) -> SyntaxNodePtr<L>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more