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.
§Note
Since the location is source code dependent, this must not be used with mutable syntax trees. Any changes made in such trees causes the pointed node’s source location to change, invalidating the pointer.
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.
Panics if the provided node is mutable
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).
NOTE: If this function is called on a mutable tree, it will panic
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 ==
.impl<L: Copy + Language> Copy for SyntaxNodePtr<L>
impl<L: Eq + Language> Eq for SyntaxNodePtr<L>
impl<L: Language> StructuralPartialEq for SyntaxNodePtr<L>
Auto Trait Implementations§
impl<L> Freeze for SyntaxNodePtr<L>
impl<L> RefUnwindSafe for SyntaxNodePtr<L>
impl<L> Send for SyntaxNodePtr<L>
impl<L> Sync for SyntaxNodePtr<L>
impl<L> Unpin for SyntaxNodePtr<L>
impl<L> UnwindSafe for SyntaxNodePtr<L>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)