From: Ian Jackson Date: Sat, 4 Jul 2020 02:09:11 +0000 (+0100) Subject: IdForById X-Git-Tag: otter-0.2.0~1477 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c9d165132d3f3aeeafa05a7b3d744fee4c2ebad2;p=otter.git IdForById --- 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; +}