add StructId

This commit is contained in:
Aleksey Kladov 2019-01-24 16:18:20 +03:00
parent 2734636c53
commit c57a857988

View file

@ -14,6 +14,7 @@ pub struct HirInterner {
defs: LocationIntener<DefLoc, DefId>,
macros: LocationIntener<MacroCallLoc, MacroCallId>,
fns: LocationIntener<FunctionLoc, FunctionId>,
structs: LocationIntener<StructLoc, StructId>,
}
impl HirInterner {
@ -194,6 +195,24 @@ impl FunctionLoc {
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StructId(RawId);
impl_arena_id!(StructId);
pub(crate) type StructLoc = ItemLoc<ast::StructDef>;
impl StructId {
pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> StructLoc {
db.as_ref().structs.id2loc(self)
}
}
impl StructLoc {
pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> StructId {
db.as_ref().structs.loc2id(&self)
}
}
/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
/// in a specific module.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]