Struct rowan::ast::SyntaxNodePtr
source · 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 moresource§impl<L: PartialEq + Language> PartialEq for SyntaxNodePtr<L>
impl<L: PartialEq + Language> PartialEq for SyntaxNodePtr<L>
source§fn eq(&self, other: &SyntaxNodePtr<L>) -> bool
fn eq(&self, other: &SyntaxNodePtr<L>) -> bool
self
and other
values to be equal, and is used
by ==
.