chiark / gitweb /
Introduce deref_to_field!
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Feb 2021 23:26:28 +0000 (23:26 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Feb 2021 23:26:37 +0000 (23:26 +0000)
NFC

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest.rs
src/utils.rs
wdriver.rs
wdriver/wdt-hand.rs
wdriver/wdt-simple.rs

index 0ecb47ab9f08d6b65bde50acb87c41e21a78e5d5..cdd09ffe525d51e44cb2744dfe007fcd3043b5c5 100644 (file)
@@ -55,6 +55,7 @@ pub use otter::ensure_eq;
 pub use otter::commands::{MgmtCommand, MgmtResponse};
 pub use otter::commands::{MgmtGameInstruction, MgmtGameResponse};
 pub use otter::commands::{MgmtGameUpdateMode};
+pub use otter::deref_to_field;
 pub use otter::gamestate::{self, Generation, PlayerId};
 pub use otter::global::InstanceName;
 pub use otter::mgmtchannel::MgmtChannel;
@@ -127,6 +128,8 @@ pub struct Instance(pub InstanceName);
 
 // ==================== Facilities for tests ====================
 
+impl AsRef<Opts> for Opts { fn as_ref(&self) -> &Opts { self } }
+
 // -------------------- Substition --------------------
 
 pub trait Substitutor {
index 47e537ed6b644bdba1fe3cb4dc5de0fba12ccb33..5354639e9558c6eb122d16f1618ad6d5af260cac 100644 (file)
@@ -273,3 +273,13 @@ pub fn toml_merge<'u,
     }
   }
 }
+
+#[macro_export]
+macro_rules! deref_to_field {
+  {$outer:ident, $inner:ty, $field:ident} => {
+    impl Deref for $outer {
+      type Target = $inner;
+      fn deref(&self) -> &$inner { &self.$field }
+    }
+  }
+}
index 1fc055a0360ec31a1df8ceec1af8a26277df1ad9..8eb97c6eb0f734fe957cbe2e5d9227096246b454 100644 (file)
@@ -365,16 +365,6 @@ fn check_window_name_sanity(name: &str) -> &str {
   name
 }
 
-#[macro_export]
-macro_rules! ctx_with_setup {
-  {$ctx:ident} => {
-    impl Deref for $ctx {
-      type Target = self::Setup;
-      fn deref(&self) -> &self::Setup { &self.su }
-    }
-  }
-}
-
 impl Setup {
   pub fn want_test(&mut self, tname: &str) -> bool {
     self.wanted_tests.wantp(tname)
index 6422e3ec93b3556c89a3731cb3ccb42ee34c6184..981f47b4ca1ced298ba70a0c7af0772be8a9a2cf 100644 (file)
@@ -9,7 +9,7 @@ struct Ctx {
   alice: Window,
   bob: Window,
 }
-ctx_with_setup!{Ctx}
+deref_to_field!{Ctx, Setup, su}
 
 const HAND: &str = "6.1";
 const ALICE: &str = "1#1";
index 13a9d2e832dc87e979d3edb35baaae42e112da0f..a6e76731fa1291785a7e963501c9b87605f0247b 100644 (file)
@@ -10,7 +10,7 @@ struct Ctx {
   bob: Window,
   spec: GameSpec,
 }
-ctx_with_setup!{Ctx}
+deref_to_field!{Ctx, Setup, su}
 
 impl Ctx {
   #[throws(AE)]