From 36865adcb946d5567fb61d3547b78fc71df58b20 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 16:40:49 +0300 Subject: Introduce HasSource trait --- crates/ra_hir/src/code_model.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'crates/ra_hir/src/code_model.rs') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 63fdca55e..765850488 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -31,6 +31,11 @@ impl From<(HirFileId, T)> for Source { } } +pub trait HasSource { + type Ast; + fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source; +} + /// 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; + fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + self.id.source(db).into() + } +} + impl Struct { pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { self.id.source(db).into() @@ -422,6 +434,13 @@ pub struct Union { pub(crate) id: StructId, } +impl HasSource for Union { + type Ast = TreeArc; + fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + 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; + fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { + self.id.source(db).into() + } +} + impl Enum { pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source> { self.id.source(db).into() -- cgit v1.2.3