From: Ian Jackson Date: Sat, 27 Jun 2020 12:54:26 +0000 (+0100) Subject: PlayerId new style X-Git-Tag: otter-0.2.0~1527 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b214985b8603ed5e55f04d4f8824a99962f5006b;p=otter.git PlayerId new style --- diff --git a/src/global.rs b/src/global.rs index 9cf260c1..6b39b44d 100644 --- a/src/global.rs +++ b/src/global.rs @@ -8,12 +8,8 @@ slotmap::new_key_type!{ pub struct ClientId; } -type SKD = slotmap::KeyData; -#[derive(Copy,Clone,PartialEq,Eq,Serialize,Deserialize,Debug)] -pub struct PlayerId (SKD); -impl slotmap::Key for PlayerId { } -impl From for PlayerId { fn from(d : SKD) -> Self { PlayerId(d) } } -impl From for SKD { fn from(p : PlayerId) -> Self { p.0 } } +visible_slotmap_key!{PlayerId} +display_consequential_impls!{PlayerId} #[derive(Clone,Debug,Eq,PartialEq,Ord,PartialOrd,Hash)] struct RawToken (String); diff --git a/src/keydata.rs b/src/keydata.rs index 44b2ea51..7b4c77d9 100644 --- a/src/keydata.rs +++ b/src/keydata.rs @@ -48,12 +48,10 @@ macro_rules! visible_slotmap_key { fn fmt(&self, f : &mut fmt::Formatter) { slotkey_write(self.0,'.',f)? } } - impl TryFrom<&str> for VisiblePieceId { + impl TryFrom<&str> for $x { type Error = AE; #[throws(AE)] - fn try_from(s : &str) -> VisiblePieceId { - VisiblePieceId(slotkey_parse(s,'.')?) - } + fn try_from(s : &str) -> $x { $x(slotkey_parse(s,'.')?) } } impl slotmap::Key for $x { }