From c266e08e66b6dff1d7a7b2cbbae331844f6f7563 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 4 Jul 2020 02:55:00 +0100 Subject: [PATCH] byid_mut --- src/bin/server.rs | 3 +-- src/error.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 2c501827..262900e4 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -68,8 +68,7 @@ fn session(form : Json) -> Result { let player = iad.ident; let c = { let mut ig = iad.g.lock().map_err(|e| anyhow!("lock poison {:?}",&e))?; - let _pl = ig.gs.players.get_mut(player) - .ok_or_else(|| anyhow!("player deleted"))?; + let _pl = ig.gs.players.byid_mut(player)?; let cl = Client { player }; let client = ig.clients.insert(cl); diff --git a/src/error.rs b/src/error.rs index 75978bda..2fe93f32 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,6 +27,8 @@ pub trait ById { type Entry; #[throws(OE)] fn byid(&self, t: Self::Id) -> &Self::Entry; + #[throws(OE)] + fn byid_mut(&mut self, t: Self::Id) -> &mut Self::Entry; } impl ById for DenseSlotMap { @@ -35,6 +37,9 @@ impl ById for DenseSlotMap { fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> { 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) + } } impl ById for SecondarySlotMap { type Id = I; @@ -42,4 +47,7 @@ impl ById for SecondarySlotMap { fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> { 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) + } } -- 2.30.2