pub trait AstNode:
Debug
+ Send
+ Sync
+ DowncastSync {
// Required methods
fn contains(node: &Node<'_>) -> bool
where Self: Sized;
fn lower(&self) -> &(dyn AstNode + 'static);
fn get_id(&self) -> usize;
fn get_parent_id(&self) -> Option<usize>;
fn get_range(&self) -> &Range;
// Provided methods
fn get_lsp_range(&self) -> Range { ... }
fn get_start_position(&self) -> Position { ... }
fn get_end_position(&self) -> Position { ... }
fn get_text<'a>(
&self,
source_code: &'a [u8],
) -> Result<&'a str, PositionError> { ... }
fn get_parent<'a>(
&'a self,
nodes: &'a [Arc<dyn AstNode>],
) -> Option<&'a Arc<dyn AstNode>> { ... }
}Expand description
Trait representing an AST node.
Required Methods§
Sourcefn contains(node: &Node<'_>) -> boolwhere
Self: Sized,
fn contains(node: &Node<'_>) -> boolwhere
Self: Sized,
Returns true if a given tree_sitter::Node matches this node type.
Sourcefn lower(&self) -> &(dyn AstNode + 'static)
fn lower(&self) -> &(dyn AstNode + 'static)
Returns the inner node as a trait object.
If the node is a struct, returns self.
Sourcefn get_id(&self) -> usize
fn get_id(&self) -> usize
Returns the unique ID of this node.
IDs are assigned when TryFrom is called and are unique within the tree.
Sourcefn get_parent_id(&self) -> Option<usize>
fn get_parent_id(&self) -> Option<usize>
Returns the ID of the parent node, if any.
Sourcefn get_range(&self) -> &Range
fn get_range(&self) -> &Range
Returns the tree_sitter::Range of this node.
Provided Methods§
Sourcefn get_lsp_range(&self) -> Range
fn get_lsp_range(&self) -> Range
Returns the LSP-compatible range of this node.
Sourcefn get_start_position(&self) -> Position
fn get_start_position(&self) -> Position
Returns the start position in LSP format.
Sourcefn get_end_position(&self) -> Position
fn get_end_position(&self) -> Position
Returns the end position in LSP format.
Sourcefn get_text<'a>(&self, source_code: &'a [u8]) -> Result<&'a str, PositionError>
fn get_text<'a>(&self, source_code: &'a [u8]) -> Result<&'a str, PositionError>
Returns the UTF-8 text slice corresponding to this node.
Returns:
Ok(&str)with the node’s source textErr(PositionError::WrongTextRange)if the range is invalidErr(PositionError::UTF8Error)if the byte slice is not valid UTF-8
Implementations§
Source§impl dyn AstNode
impl dyn AstNode
Sourcepub fn is<__T>(&self) -> boolwhere
__T: AstNode,
pub fn is<__T>(&self) -> boolwhere
__T: AstNode,
Returns true if the trait object wraps an object of type __T.
Sourcepub fn downcast<__T>(
self: Box<dyn AstNode>,
) -> Result<Box<__T>, Box<dyn AstNode>>where
__T: AstNode,
pub fn downcast<__T>(
self: Box<dyn AstNode>,
) -> Result<Box<__T>, Box<dyn AstNode>>where
__T: AstNode,
Returns a boxed object from a boxed trait object if the underlying object is of type
__T. Returns the original boxed trait if it isn’t.
Sourcepub fn downcast_rc<__T>(
self: Rc<dyn AstNode>,
) -> Result<Rc<__T>, Rc<dyn AstNode>>where
__T: AstNode,
pub fn downcast_rc<__T>(
self: Rc<dyn AstNode>,
) -> Result<Rc<__T>, Rc<dyn AstNode>>where
__T: AstNode,
Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of
type __T. Returns the original Rc-ed trait if it isn’t.
Sourcepub fn downcast_ref<__T>(&self) -> Option<&__T>where
__T: AstNode,
pub fn downcast_ref<__T>(&self) -> Option<&__T>where
__T: AstNode,
Returns a reference to the object within the trait object if it is of type __T, or
None if it isn’t.
Sourcepub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where
__T: AstNode,
pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where
__T: AstNode,
Returns a mutable reference to the object within the trait object if it is of type
__T, or None if it isn’t.