From: Ian Jackson Date: Mon, 22 Feb 2021 00:01:29 +0000 (+0000) Subject: Soup up deref_to_field and use more X-Git-Tag: otter-0.4.0~384 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=dbd296393653531cf636c1cee305364dad8cfb7e;p=otter.git Soup up deref_to_field and use more Signed-off-by: Ian Jackson --- diff --git a/apitest.rs b/apitest.rs index cdd09ffe..a6fd5dad 100644 --- a/apitest.rs +++ b/apitest.rs @@ -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; diff --git a/src/utils.rs b/src/utils.rs index 02fb9dfe..e8d86826 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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)* } } } diff --git a/wdriver.rs b/wdriver.rs index 67884498..3f753eb4 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -50,14 +50,7 @@ pub struct Setup { final_hook: FinalInfoCollection, windows_squirreled: Vec, // 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)]