From: Ian Jackson Date: Sat, 4 Jul 2020 02:16:42 +0000 (+0100) Subject: macro X-Git-Tag: otter-0.2.0~1475 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a84b382d5efa02822cbdec5c344422ad9a10f7c0;p=otter.git macro --- diff --git a/src/error.rs b/src/error.rs index b8c77e4b..53271619 100644 --- a/src/error.rs +++ b/src/error.rs @@ -45,29 +45,25 @@ pub trait IdForById { const ERROR : Self::Error; } -impl ById for DenseSlotMap { - type Id = I; - type Entry = T; - type Error = ::Error; - fn byid(&self, t: Self::Id) -> Result<&Self::Entry, Self::Error> { - self.get(t).ok_or(::ERROR) - } - fn byid_mut(&mut self, t: Self::Id) -> Result<&mut Self::Entry, Self::Error> { - self.get_mut(t).ok_or(::ERROR) - } -} -impl ById for SecondarySlotMap { - type Id = I; - type Entry = T; - type Error = ::Error; - fn byid(&self, t: Self::Id) -> Result<&Self::Entry, Self::Error> { - self.get(t).ok_or(::ERROR) - } - fn byid_mut(&mut self, t: Self::Id) -> Result<&mut Self::Entry, Self::Error> { - self.get_mut(t).ok_or(::ERROR) +macro_rules! some_slotmap { + ($slotmap:ident) => { + impl ById for $slotmap { + type Id = I; + type Entry = T; + type Error = ::Error; + fn byid (& self, t: Self::Id) -> Result<& T, Self::Error> { + self.get (t).ok_or(::ERROR) + } + fn byid_mut(&mut self, t: Self::Id) -> Result<&mut T, Self::Error> { + self.get_mut(t).ok_or(::ERROR) + } + } } } +some_slotmap!{DenseSlotMap} +some_slotmap!{SecondarySlotMap} + impl IdForById for T where T : AccessId { type Error = OE; const ERROR : OE = ::ERROR;