chiark / gitweb /
Soup up deref_to_field and use more
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 22 Feb 2021 00:01:29 +0000 (00:01 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 22 Feb 2021 00:01:38 +0000 (00:01 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest.rs
src/utils.rs
wdriver.rs

index cdd09ffe525d51e44cb2744dfe007fcd3043b5c5..a6fd5dadbe4963fae0b1aec65a24ac713eb8fbcb 100644 (file)
@@ -55,7 +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::{deref_to_field, deref_to_field_mut};
 pub use otter::gamestate::{self, Generation, PlayerId};
 pub use otter::global::InstanceName;
 pub use otter::mgmtchannel::MgmtChannel;
index 02fb9dfe5761def68f9b1cfa49cfcba042951a2c..e8d86826a996500c32b1ec9f3f313991d3eb4bb7 100644 (file)
@@ -276,8 +276,8 @@ pub fn toml_merge<'u,
 
 #[macro_export]
 macro_rules! deref_to_field {
-  {$outer:ty, $inner:ty, $($field:tt)*} => {
-    impl Deref for $outer {
+  {$({ $($gen:tt)* })? $outer:ty, $inner:ty, $($field:tt)*} => {
+    impl $(< $($gen)* >)? Deref for $outer {
       type Target = $inner;
       fn deref(&self) -> &$inner { &self.$($field)* }
     }
@@ -285,9 +285,9 @@ macro_rules! deref_to_field {
 }
 #[macro_export]
 macro_rules! deref_to_field_mut {
-  {$outer:ty, $inner:ty, $($field:tt)*} => {
-    deref_to_field!{$outer, $inner, $($field)*}
-    impl DerefMut for $outer {
+  {$({ $($gen:tt)* })? $outer:ty, $inner:ty, $($field:tt)*} => {
+    deref_to_field!{ $({ $($gen)* })? $outer, $inner, $($field)*}
+    impl $(< $($gen)* >)? DerefMut for $outer {
       fn deref_mut(&mut self) -> &mut $inner { &mut self.$($field)* }
     }
   }
index 67884498355a732edea52049fc4b43fb05867dc2..3f753eb42ccb630dfef7571281492fbf104d2cce 100644 (file)
@@ -50,14 +50,7 @@ pub struct Setup {
   final_hook: FinalInfoCollection,
   windows_squirreled: Vec<String>, // see Drop impl
 }
-
-impl Deref for Setup {
-  type Target = SetupCore;
-  fn deref(&self) -> &SetupCore { &self.core }
-}
-impl DerefMut for Setup {
-  fn deref_mut(&mut self) -> &mut SetupCore { &mut self.core }
-}
+deref_to_field_mut!{Setup, SetupCore, core}
 
 #[derive(Debug)]
 pub struct Window {
@@ -309,11 +302,7 @@ pub struct PieceElement<'g> {
   w: &'g WindowGuard<'g>,
   elem: t4::WebElement<'g>,
 }
-
-impl<'g> Deref for PieceElement<'g> {
-  type Target = t4::WebElement<'g>;
-  fn deref<'i>(&'i self) -> &'i t4::WebElement<'g> { &self.elem }
-}
+deref_to_field!{{'g} PieceElement<'g>, t4::WebElement<'g>, elem}
 
 impl<'g> PieceElement<'g> {
   #[throws(AE)]