From: Ian Jackson Date: Sat, 27 Jun 2020 12:08:40 +0000 (+0100) Subject: wip keydata reorg X-Git-Tag: otter-0.2.0~1535 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7a002ae3ff9467e8cdbf7fe9c0b0b0e91682b3ad;p=otter.git wip keydata reorg --- diff --git a/src/gamestate.rs b/src/gamestate.rs index 98ddebe0..d8e4d26e 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -23,14 +23,7 @@ impl Display for VisiblePieceId { write!(f, "{}.{}", self.0 >> 32, self.0 & 0xffffffff) } } -impl Debug for VisiblePieceId { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - ::fmt(self, f) - } -} -impl From for String { - fn from(p: VisiblePieceId) -> String { format!("{}",p) } -} +display_consequential_impls!{VisiblePieceId} impl TryFrom<&str> for VisiblePieceId { type Error = AE; diff --git a/src/imports.rs b/src/imports.rs index 08b5e331..61070b8c 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -33,6 +33,7 @@ pub use index_vec::{define_index_type,index_vec,IndexVec}; pub use crate::global::*; pub use crate::gamestate::*; pub use crate::pieces::*; +pub use crate::keydata::*; pub type E = anyhow::Error; pub type AE = anyhow::Error; diff --git a/src/keydata.rs b/src/keydata.rs new file mode 100644 index 00000000..9352892d --- /dev/null +++ b/src/keydata.rs @@ -0,0 +1,16 @@ + +#[macro_export] +macro_rules! display_consequential_impls { + ( $x:path ) => { + impl From<$x> for String { + fn from(p : $x) -> String { format!("{}",p) } + } + impl Debug for $x { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + ::fmt(self, f) + } + } + } +} + +pub use crate::display_consequential_impls; // this is madness! diff --git a/src/lib.rs b/src/lib.rs index 62de69ea..5096c9ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,3 +3,4 @@ pub mod imports; pub mod global; pub mod pieces; pub mod gamestate; +pub mod keydata;