mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Introduce HasSource trait
This commit is contained in:
parent
2a1fe26b6d
commit
36865adcb9
3 changed files with 45 additions and 29 deletions
|
@ -31,6 +31,11 @@ impl<T> From<(HirFileId, T)> for Source<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HasSource {
|
||||
type Ast;
|
||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>;
|
||||
}
|
||||
|
||||
/// hir::Crate describes a single crate. It's the main interface with which
|
||||
/// a crate's dependencies interact. Mostly, it should be just a proxy for the
|
||||
/// root module.
|
||||
|
@ -364,6 +369,13 @@ pub struct Struct {
|
|||
pub(crate) id: StructId,
|
||||
}
|
||||
|
||||
impl HasSource for Struct {
|
||||
type Ast = TreeArc<ast::StructDef>;
|
||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
|
||||
self.id.source(db).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Struct {
|
||||
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
|
||||
self.id.source(db).into()
|
||||
|
@ -422,6 +434,13 @@ pub struct Union {
|
|||
pub(crate) id: StructId,
|
||||
}
|
||||
|
||||
impl HasSource for Union {
|
||||
type Ast = TreeArc<ast::StructDef>;
|
||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
|
||||
self.id.source(db).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Union {
|
||||
pub fn source(
|
||||
self,
|
||||
|
@ -455,6 +474,13 @@ pub struct Enum {
|
|||
pub(crate) id: EnumId,
|
||||
}
|
||||
|
||||
impl HasSource for Enum {
|
||||
type Ast = TreeArc<ast::EnumDef>;
|
||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
|
||||
self.id.source(db).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Enum {
|
||||
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
|
||||
self.id.source(db).into()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue