chiark / gitweb /
visible slotmap keys: handle null specially
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Feb 2021 01:13:18 +0000 (01:13 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Feb 2021 01:13:18 +0000 (01:13 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
src/global.rs
src/keydata.rs

index de075fca239b3e670b292313111eb684492ebc3c..f0c03bec4dc5408c20164a52ebd5adb186467290 100644 (file)
@@ -8,7 +8,7 @@ type SE = SVGProcessingError;
 
 // ---------- newtypes and type aliases ----------
 
-visible_slotmap_key!{ PlayerId('#') }
+visible_slotmap_key!{ PlayerId(b'#') }
 
 slotmap::new_key_type!{
   pub struct PieceId;
@@ -19,7 +19,7 @@ slotmap::new_key_type!{
 #[serde(transparent)]
 pub struct Generation(pub u64);
 
-visible_slotmap_key!{ VisiblePieceId('.') }
+visible_slotmap_key!{ VisiblePieceId(b'.') }
 
 #[derive(Clone,Copy,Debug)]
 #[derive(Serialize,Deserialize)]
index 2e115715609bfa362cbb07162950cb047c59464e..df1c6b8b2fd24e77a3b8c0418046e9794d642e33 100644 (file)
@@ -13,7 +13,7 @@ use std::sync::PoisonError;
 
 // ---------- newtypes and type aliases ----------
 
-visible_slotmap_key!{ ClientId('C') }
+visible_slotmap_key!{ ClientId(b'C') }
 
 const MAX_CLIENT_INACTIVITY: Duration = Duration::from_secs(200);
 
index 291e91ceec91bfadc12a6408635192baa457006d..89d5e84684c1c346587b969e3273673e42eb0d4a 100644 (file)
@@ -24,7 +24,9 @@ macro_rules! display_consequential_impls {
 pub use crate::display_consequential_impls; // this is madness!
 
 #[throws(AE)]
-pub fn slotkey_parse(s: &str, sep: char) -> SKD {
+pub fn slotkey_parse(s: &str, sep: u8) -> SKD {
+  if s.as_bytes() == [b'0', sep, b'0', b'0'] { return default() }
+  let sep: char = sep.into();
   let e = || anyhow!("could not deserialise visibile piece id");
   let mut i = s.splitn(2, sep).map(|s| s.parse().map_err(|_| e()));
   let l: u32 = i.next().ok_or_else(e)??;
@@ -34,7 +36,9 @@ pub fn slotkey_parse(s: &str, sep: char) -> SKD {
 }
 
 #[throws(fmt::Error)]
-pub fn slotkey_write(k: SKD, sep: char, f: &mut fmt::Formatter) {
+pub fn slotkey_write(k: SKD, sep: u8, f: &mut fmt::Formatter) {
+  let sep: char = sep.into();
+  if k == default() { write!(f, "0{}00", sep)?; return; }
   let v = k.as_ffi();
   write!(f, "{}{}{}", v & 0xffffffff, sep, v >> 32)?
 }