From 4e683d7af1d752f2d7bc6e2ed4d6b85405bc84a8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Nov 2018 14:52:10 +0300 Subject: Add ModId --- crates/ra_analysis/src/loc2id.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/loc2id.rs b/crates/ra_analysis/src/loc2id.rs index 8eaa24997..53bf609fa 100644 --- a/crates/ra_analysis/src/loc2id.rs +++ b/crates/ra_analysis/src/loc2id.rs @@ -72,17 +72,26 @@ pub(crate) trait NumericId: Clone + Eq + Hash { fn to_u32(self) -> u32; } +macro_rules! impl_numeric_id { + ($id:ident) => { + impl NumericId for $id { + fn from_u32(id: u32) -> Self { + $id(id) + } + fn to_u32(self) -> u32 { + self.0 + } + } + }; +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct FnId(u32); +impl_numeric_id!(FnId); -impl NumericId for FnId { - fn from_u32(id: u32) -> FnId { - FnId(id) - } - fn to_u32(self) -> u32 { - self.0 - } -} +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) struct ModId(u32); +impl_numeric_id!(ModId); pub(crate) trait IdDatabase: salsa::Database { fn id_maps(&self) -> &IdMaps; -- cgit v1.2.3