chiark / gitweb /
byid_mut
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 01:55:00 +0000 (02:55 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 01:55:08 +0000 (02:55 +0100)
src/bin/server.rs
src/error.rs

index 2c501827a50ec5aa7adc5c3bf18a55e7d442fbf9..262900e497850bd20422690b5bfb5f13e71e8a5f 100644 (file)
@@ -68,8 +68,7 @@ fn session(form : Json<SessionForm>) -> Result<Template,RE> {
   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);
 
index 75978bda137a9507e024456506a1c5cd40fc1356..2fe93f327d180a5a014f78a360be1b6799017cb1 100644 (file)
@@ -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<I:AccessId+slotmap::Key, T> ById for DenseSlotMap<I,T> {
@@ -35,6 +37,9 @@ impl<I:AccessId+slotmap::Key, T> ById for DenseSlotMap<I,T> {
   fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> {
     self.get(t).ok_or(<I as AccessId>::ERROR)
   }
+  fn byid_mut(&mut self, t: Self::Id) -> Result<&mut Self::Entry, OE> {
+    self.get_mut(t).ok_or(<I as AccessId>::ERROR)
+  }
 }
 impl<I:AccessId+slotmap::Key, T> ById for SecondarySlotMap<I,T> {
   type Id = I;
@@ -42,4 +47,7 @@ impl<I:AccessId+slotmap::Key, T> ById for SecondarySlotMap<I,T> {
   fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> {
     self.get(t).ok_or(<I as AccessId>::ERROR)
   }
+  fn byid_mut(&mut self, t: Self::Id) -> Result<&mut Self::Entry, OE> {
+    self.get_mut(t).ok_or(<I as AccessId>::ERROR)
+  }
 }