From b214985b8603ed5e55f04d4f8824a99962f5006b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 27 Jun 2020 13:54:26 +0100 Subject: [PATCH] PlayerId new style --- src/global.rs | 8 ++------ src/keydata.rs | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) 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 { } -- 2.30.2