pub enum HirNode<'hir> {
Undefined,
Root(&'hir HirRoot),
Text(&'hir HirText<'hir>),
Internal(&'hir HirInternal),
Scope(&'hir HirScope<'hir>),
File(&'hir HirFile),
Ident(&'hir HirIdent<'hir>),
}Variants§
Undefined
Root(&'hir HirRoot)
Text(&'hir HirText<'hir>)
Internal(&'hir HirInternal)
Scope(&'hir HirScope<'hir>)
File(&'hir HirFile)
Ident(&'hir HirIdent<'hir>)
Implementations§
Source§impl<'hir> HirNode<'hir>
impl<'hir> HirNode<'hir>
pub fn format(&self, _unit: CompileUnit<'hir>) -> String
Sourcepub fn field_id(&self) -> u16
pub fn field_id(&self) -> u16
Get the field ID of this node (used in structured tree navigation)
For example, in a function declaration, the name field might have field_id=1 and the body field_id=2. Panics on Undefined node.
Sourcepub fn children(&self, unit: &CompileUnit<'hir>) -> SmallVec<[HirNode<'hir>; 8]>
pub fn children(&self, unit: &CompileUnit<'hir>) -> SmallVec<[HirNode<'hir>; 8]>
Get children nodes of this node - uses SmallVec to avoid heap allocation for small child counts
Sourcepub fn id(&self) -> HirId
pub fn id(&self) -> HirId
Get unique HirId for this node within its compilation unit. Panics on Undefined.
Sourcepub fn start_byte(&self) -> usize
pub fn start_byte(&self) -> usize
Get byte offset where this node starts in source. Panics on Undefined.
Sourcepub fn end_byte(&self) -> usize
pub fn end_byte(&self) -> usize
Get byte offset where this node ends (exclusive). Panics on Undefined.
Sourcepub fn child_count(&self) -> usize
pub fn child_count(&self) -> usize
Get count of direct children
Sourcepub fn child_by_field(
&self,
unit: &CompileUnit<'hir>,
field_id: u16,
) -> Option<HirNode<'hir>>
pub fn child_by_field( &self, unit: &CompileUnit<'hir>, field_id: u16, ) -> Option<HirNode<'hir>>
Find optional child with matching field ID
pub fn child_by_kind( &self, unit: &CompileUnit<'hir>, kind_id: u16, ) -> Option<HirNode<'hir>>
Sourcepub fn ident_symbol_by_field(
&self,
unit: &CompileUnit<'hir>,
field_id: u16,
) -> Option<&'hir Symbol>
pub fn ident_symbol_by_field( &self, unit: &CompileUnit<'hir>, field_id: u16, ) -> Option<&'hir Symbol>
Returns the symbol referenced by the identifier within a specific child field.
Sourcepub fn ident_symbol(&self, unit: &CompileUnit<'hir>) -> Option<&'hir Symbol>
pub fn ident_symbol(&self, unit: &CompileUnit<'hir>) -> Option<&'hir Symbol>
Returns the ident symbol if any. Prefers finding an identifier that has a symbol set (useful for scoped paths where the target identifier has the resolved symbol).
Sourcepub fn child_by_field_recursive(
&self,
unit: &CompileUnit<'hir>,
field_id: u16,
) -> Option<HirNode<'hir>>
pub fn child_by_field_recursive( &self, unit: &CompileUnit<'hir>, field_id: u16, ) -> Option<HirNode<'hir>>
Recursively search down the tree for a child with matching field ID. Keeps going deeper until it finds a match or reaches a leaf node.
Sourcepub fn find_ident(
&self,
unit: &CompileUnit<'hir>,
) -> Option<&'hir HirIdent<'hir>>
pub fn find_ident( &self, unit: &CompileUnit<'hir>, ) -> Option<&'hir HirIdent<'hir>>
Find the identifier for the first child node that is an identifier or interior node. Recursively searches for identifiers within interior nodes.
Sourcepub fn find_symboled_ident(
&self,
unit: &CompileUnit<'hir>,
) -> Option<&'hir HirIdent<'hir>>
pub fn find_symboled_ident( &self, unit: &CompileUnit<'hir>, ) -> Option<&'hir HirIdent<'hir>>
Find the deepest/rightmost identifier that has a symbol set.
This is useful for call expressions where we want the resolved callee,
not just the first identifier in a scoped path like crate::module::func.
Sourcepub fn find_text(&self, unit: &CompileUnit<'hir>) -> Option<&str>
pub fn find_text(&self, unit: &CompileUnit<'hir>) -> Option<&str>
Find the first text node’s content in children (for keywords like “self”).
Sourcepub fn ident_by_field(
&self,
unit: &CompileUnit<'hir>,
field_id: u16,
) -> Option<&'hir HirIdent<'hir>>
pub fn ident_by_field( &self, unit: &CompileUnit<'hir>, field_id: u16, ) -> Option<&'hir HirIdent<'hir>>
Find identifier for the first child with a matching field ID.
For scoped types like crate::module::Type, returns Type (the direct type_identifier child).
For generic types like Repository<User>, recurses into the type child to get Repository.
pub fn as_root(&self) -> Option<&'hir HirRoot>
pub fn as_text(&self) -> Option<&'hir HirText<'hir>>
pub fn as_scope(&self) -> Option<&'hir HirScope<'hir>>
Sourcepub fn scope_and_ident_by_field(
&self,
unit: &CompileUnit<'hir>,
field_id: u16,
) -> Option<(&'hir HirScope<'hir>, &'hir HirIdent<'hir>)>
pub fn scope_and_ident_by_field( &self, unit: &CompileUnit<'hir>, field_id: u16, ) -> Option<(&'hir HirScope<'hir>, &'hir HirIdent<'hir>)>
Get scope and child identifier by field - convenience method combining as_scope() and ident_by_field()
Sourcepub fn collect_by_field_kind(
&self,
unit: &CompileUnit<'hir>,
field_id: u16,
) -> Vec<&'hir HirIdent<'hir>>
pub fn collect_by_field_kind( &self, unit: &CompileUnit<'hir>, field_id: u16, ) -> Vec<&'hir HirIdent<'hir>>
Collect identifiers by field kind matching a specific field ID
pub fn as_file(&self) -> Option<&'hir HirFile>
pub fn as_internal(&self) -> Option<&'hir HirInternal>
pub fn as_ident(&self) -> Option<&'hir HirIdent<'hir>>
Sourcepub fn collect_idents(
&self,
unit: &CompileUnit<'hir>,
) -> Vec<&'hir HirIdent<'hir>>
pub fn collect_idents( &self, unit: &CompileUnit<'hir>, ) -> Vec<&'hir HirIdent<'hir>>
Recursively collect all identifier nodes under this node
Sourcepub fn set_block_id(&self, block_id: BlockId)
pub fn set_block_id(&self, block_id: BlockId)
Set the block ID on the symbol associated with this node. Works for both HirScope (gets symbol from scope) and HirIdent (has direct symbol). Does nothing if no symbol is associated or if the symbol is a primitive (shared globally).
Sourcepub fn opt_symbol(&self) -> Option<&'hir Symbol>
pub fn opt_symbol(&self) -> Option<&'hir Symbol>
Get the symbol associated with this node if any. Works for both HirScope and HirIdent nodes.
Trait Implementations§
Source§impl<'a> ArenaInsert<'a> for HirNode<'a>
impl<'a> ArenaInsert<'a> for HirNode<'a>
fn insert_into(self, arena: &'a ArenaInner) -> &'a Self
Source§impl<'a> ArenaInsertWithId<'a> for HirNode<'a>
impl<'a> ArenaInsertWithId<'a> for HirNode<'a>
fn insert_with_id(self, arena: &'a ArenaInner, id: usize) -> &'a Self
impl<'hir> Copy for HirNode<'hir>
Auto Trait Implementations§
impl<'hir> Freeze for HirNode<'hir>
impl<'hir> !RefUnwindSafe for HirNode<'hir>
impl<'hir> Send for HirNode<'hir>
impl<'hir> Sync for HirNode<'hir>
impl<'hir> Unpin for HirNode<'hir>
impl<'hir> !UnwindSafe for HirNode<'hir>
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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more