From c9d165132d3f3aeeafa05a7b3d744fee4c2ebad2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 4 Jul 2020 03:09:11 +0100 Subject: [PATCH] IdForById --- src/error.rs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/error.rs b/src/error.rs index 75c8b9ff..54a0aa9a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -32,25 +32,35 @@ pub trait ById { fn byid_mut(&mut self, t: Self::Id) -> &mut Self::Entry; } -impl ById for DenseSlotMap { +pub trait IdForById { + type Error; + const ERROR : Self::Error; +} + +impl ById for DenseSlotMap { type Id = I; type Entry = T; - type Error = OE; - fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> { - self.get(t).ok_or(::ERROR) + 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, OE> { - self.get_mut(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 { +impl ById for SecondarySlotMap { type Id = I; type Entry = T; - type Error = OE; - fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> { - self.get(t).ok_or(::ERROR) + 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, OE> { - self.get_mut(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 IdForById for T where T : AccessId { + type Error = OE; + const ERROR : OE = ::ERROR; +} -- 2.30.2