pub trait HasSource: Sized {
type Ast: AstNode;
// Required method
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>>;
// Provided method
fn source_with_range(
self,
db: &dyn HirDatabase,
) -> Option<InFile<(TextRange, Option<Self::Ast>)>> { ... }
}Required Associated Types§
Required Methods§
Sourcefn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>>
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>>
Fetches the definition’s source node.
Using crate::SemanticsImpl::source is preferred when working with crate::Semantics,
as that caches the parsed file in the semantics’ cache.
The current some implementations can return InFile instead of Option<InFile>.
But we made this method Option to support rlib in the future
by https://github.com/rust-lang/rust-analyzer/issues/6913
Provided Methods§
Sourcefn source_with_range(
self,
db: &dyn HirDatabase,
) -> Option<InFile<(TextRange, Option<Self::Ast>)>>
fn source_with_range( self, db: &dyn HirDatabase, ) -> Option<InFile<(TextRange, Option<Self::Ast>)>>
Fetches the source node, along with its full range.
The reason for the separate existence of this method is that some things, notably builtin derive impls, do not really have a source node, at least not of the correct type. But we still can trace them to source code (the derive producing them). So this method will return the range if it is supported, and if the node is supported too it will return it as well.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.