aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-11 14:40:49 +0100
committerAleksey Kladov <[email protected]>2019-06-11 16:28:51 +0100
commit36865adcb946d5567fb61d3547b78fc71df58b20 (patch)
tree4cec6a3d18de8242c334fe303717c1f2b1c42be1 /crates/ra_hir/src/code_model.rs
parent2a1fe26b6d354dbbd1b3843d288d56e74fa00557 (diff)
Introduce HasSource trait
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs26
1 files changed, 26 insertions, 0 deletions
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<T> From<(HirFileId, T)> for Source<T> {
31 } 31 }
32} 32}
33 33
34pub trait HasSource {
35 type Ast;
36 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>;
37}
38
34/// hir::Crate describes a single crate. It's the main interface with which 39/// hir::Crate describes a single crate. It's the main interface with which
35/// a crate's dependencies interact. Mostly, it should be just a proxy for the 40/// a crate's dependencies interact. Mostly, it should be just a proxy for the
36/// root module. 41/// root module.
@@ -364,6 +369,13 @@ pub struct Struct {
364 pub(crate) id: StructId, 369 pub(crate) id: StructId,
365} 370}
366 371
372impl HasSource for Struct {
373 type Ast = TreeArc<ast::StructDef>;
374 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
375 self.id.source(db).into()
376 }
377}
378
367impl Struct { 379impl Struct {
368 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { 380 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
369 self.id.source(db).into() 381 self.id.source(db).into()
@@ -422,6 +434,13 @@ pub struct Union {
422 pub(crate) id: StructId, 434 pub(crate) id: StructId,
423} 435}
424 436
437impl HasSource for Union {
438 type Ast = TreeArc<ast::StructDef>;
439 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
440 self.id.source(db).into()
441 }
442}
443
425impl Union { 444impl Union {
426 pub fn source( 445 pub fn source(
427 self, 446 self,
@@ -455,6 +474,13 @@ pub struct Enum {
455 pub(crate) id: EnumId, 474 pub(crate) id: EnumId,
456} 475}
457 476
477impl HasSource for Enum {
478 type Ast = TreeArc<ast::EnumDef>;
479 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
480 self.id.source(db).into()
481 }
482}
483
458impl Enum { 484impl Enum {
459 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> { 485 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
460 self.id.source(db).into() 486 self.id.source(db).into()