From: Ian Jackson Date: Sat, 27 Jun 2020 12:57:46 +0000 (+0100) Subject: fix playerid X-Git-Tag: otter-0.2.0~1526 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=14882c692b1bf3c172bd2993a18bf463a05221fc;p=otter.git fix playerid --- diff --git a/src/gamestate.rs b/src/gamestate.rs index 244edf7b..042de128 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -5,8 +5,7 @@ slotmap::new_key_type!{ pub struct PieceId; } -visible_slotmap_key!{VisiblePieceId} -display_consequential_impls!{VisiblePieceId} +visible_slotmap_key!{ VisiblePieceId('.') } pub fn make_pieceid_visible(p : PieceId) -> VisiblePieceId { // xxx need to do censorship mapping here diff --git a/src/global.rs b/src/global.rs index 6b39b44d..8a97b467 100644 --- a/src/global.rs +++ b/src/global.rs @@ -8,8 +8,7 @@ slotmap::new_key_type!{ pub struct ClientId; } -visible_slotmap_key!{PlayerId} -display_consequential_impls!{PlayerId} +visible_slotmap_key!{ PlayerId('#') } #[derive(Clone,Debug,Eq,PartialEq,Ord,PartialOrd,Hash)] struct RawToken (String); diff --git a/src/keydata.rs b/src/keydata.rs index 7b4c77d9..2b8799b7 100644 --- a/src/keydata.rs +++ b/src/keydata.rs @@ -36,7 +36,7 @@ pub fn slotkey_write(k : SKD, sep : char, f : &mut fmt::Formatter) { #[macro_export] macro_rules! visible_slotmap_key { - ( $x:ident ) => { + ( $x:ident($sep:expr) ) => { #[derive(Copy,Clone,Eq,PartialEq,Ord,PartialOrd,Serialize,Deserialize)] #[serde(into="String")] @@ -45,13 +45,13 @@ macro_rules! visible_slotmap_key { impl Display for $x { #[throws(fmt::Error)] - fn fmt(&self, f : &mut fmt::Formatter) { slotkey_write(self.0,'.',f)? } + fn fmt(&self, f : &mut fmt::Formatter) { slotkey_write(self.0,$sep,f)? } } impl TryFrom<&str> for $x { type Error = AE; #[throws(AE)] - fn try_from(s : &str) -> $x { $x(slotkey_parse(s,'.')?) } + fn try_from(s : &str) -> $x { $x(slotkey_parse(s,$sep)?) } } impl slotmap::Key for $x { } @@ -63,6 +63,8 @@ macro_rules! visible_slotmap_key { p.0 } } + + display_consequential_impls!{$x} } } pub use crate::visible_slotmap_key; // this is madness!