rust/crates/ra_hir_def/src/src.rs
Aleksey Kladov 9faea2364d Use dyn Trait for working with databse
It improves compile time in `--release` mode quite a bit, it doesn't
really slow things down and, conceptually, it seems closer to what we
want the physical architecture to look like (we don't want to
monomorphise EVERYTHING in a single leaf crate).
2020-03-16 17:42:30 +01:00

37 lines
937 B
Rust

//! Utilities for mapping between hir IDs and the surface syntax.
use hir_expand::InFile;
use ra_arena::map::ArenaMap;
use ra_syntax::AstNode;
use crate::{db::DefDatabase, AssocItemLoc, ItemLoc};
pub trait HasSource {
type Value;
fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>;
}
impl<N: AstNode> HasSource for AssocItemLoc<N> {
type Value = N;
fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
let node = self.ast_id.to_node(db.upcast());
InFile::new(self.ast_id.file_id, node)
}
}
impl<N: AstNode> HasSource for ItemLoc<N> {
type Value = N;
fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
let node = self.ast_id.to_node(db.upcast());
InFile::new(self.ast_id.file_id, node)
}
}
pub trait HasChildSource {
type ChildId;
type Value;
fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
}