HasSource

Trait HasSource 

Source
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§

Source

type Ast: AstNode

Required Methods§

Source

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§

Source

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.

Implementors§

Source§

impl HasSource for Adt

Source§

type Ast = Adt

Source§

impl HasSource for Variant

Source§

type Ast = VariantDef

Source§

impl HasSource for Const

Source§

type Ast = Const

Source§

impl HasSource for Enum

Source§

type Ast = Enum

Source§

impl HasSource for EnumVariant

Source§

type Ast = Variant

Source§

impl HasSource for ExternCrateDecl

Source§

type Ast = ExternCrate

Source§

impl HasSource for Field

Source§

impl HasSource for Function

Source§

type Ast = Fn

Source§

impl HasSource for Impl

Source§

type Ast = Impl

Source§

impl HasSource for InlineAsmOperand

Source§

type Ast = AsmOperandNamed

Source§

impl HasSource for Label

Source§

type Ast = Label

Source§

impl HasSource for LifetimeParam

Source§

type Ast = LifetimeParam

Source§

impl HasSource for LocalSource

Source§

type Ast = Either<IdentPat, SelfParam>

Source§

impl HasSource for Macro

Source§

type Ast = Either<Macro, Fn>

Source§

impl HasSource for Param<'_>

Source§

type Ast = Either<SelfParam, Param>

Source§

impl HasSource for SelfParam

Source§

type Ast = SelfParam

Source§

impl HasSource for Static

Source§

type Ast = Static

Source§

impl HasSource for Struct

Source§

type Ast = Struct

Source§

impl HasSource for Trait

Source§

type Ast = Trait

Source§

impl HasSource for TypeAlias

Source§

type Ast = TypeAlias

Source§

impl HasSource for TypeOrConstParam

Source§

type Ast = Either<TypeOrConstParam, Trait>

Source§

impl HasSource for Union

Source§

type Ast = Union