From 53c2560a1fc366936ea0a635f9c463745118d5af Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 21 Feb 2021 23:26:28 +0000 Subject: [PATCH] Introduce deref_to_field! NFC Signed-off-by: Ian Jackson --- apitest.rs | 3 +++ src/utils.rs | 10 ++++++++++ wdriver.rs | 10 ---------- wdriver/wdt-hand.rs | 2 +- wdriver/wdt-simple.rs | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/apitest.rs b/apitest.rs index 0ecb47ab..cdd09ffe 100644 --- a/apitest.rs +++ b/apitest.rs @@ -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 for Opts { fn as_ref(&self) -> &Opts { self } } + // -------------------- Substition -------------------- pub trait Substitutor { diff --git a/src/utils.rs b/src/utils.rs index 47e537ed..5354639e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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 } + } + } +} diff --git a/wdriver.rs b/wdriver.rs index 1fc055a0..8eb97c6e 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -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) diff --git a/wdriver/wdt-hand.rs b/wdriver/wdt-hand.rs index 6422e3ec..981f47b4 100644 --- a/wdriver/wdt-hand.rs +++ b/wdriver/wdt-hand.rs @@ -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"; diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 13a9d2e8..a6e76731 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -10,7 +10,7 @@ struct Ctx { bob: Window, spec: GameSpec, } -ctx_with_setup!{Ctx} +deref_to_field!{Ctx, Setup, su} impl Ctx { #[throws(AE)] -- 2.30.2