From 52e0a44d140070f24c3f79e4ac3c5ab57486826b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 28 Jan 2021 17:05:06 +0000 Subject: [PATCH] wdt: new move_pos extension method Signed-off-by: Ian Jackson --- wdriver.rs | 17 +++++++++++++++++ wdriver/wdt-simple.rs | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/wdriver.rs b/wdriver.rs index cdcdf55f..31d948a8 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -893,6 +893,14 @@ impl<'g> PieceElement<'g> { } } +impl<'g> TryInto for &'g PieceElement<'g> { + type Error = AE; + #[throws(AE)] + fn try_into(self) -> WebPos { + self.posw()? + } +} + #[throws(AE)] fn check_window_name_sanity(name: &str) -> &str { let e = || anyhow!("bad window name {:?}", &name); @@ -1122,6 +1130,9 @@ impl IntoInWindow for Pos { pub trait ActionChainExt: Sized { fn w_move<'g, P: IntoInWindow> (self, w: &'g WindowGuard, pos: P) -> Result; + + fn move_pos<'g, P: TryInto> + (self, pos: P) -> Result; } impl<'a> ActionChainExt for t4::action_chain::ActionChain<'a> { @@ -1132,6 +1143,12 @@ impl<'a> ActionChainExt for t4::action_chain::ActionChain<'a> { let (px,py) = pos.w_into(w)?; self.move_to(px,py) } + + #[throws(AE)] + fn move_pos<'g, P: TryInto> (self, pos: P) -> Self { + let (px,py) = pos.try_into()?; + self.move_to(px,py) + } } impl Drop for Setup { diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 66e39e1f..4425d18d 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -26,7 +26,7 @@ impl Ctx { let (p2x,p2y) = p2.posw()?; w.action_chain() - .w_move(&w, p1.posw()?)? + .move_pos(&p1)? .click_and_hold() .move_to(p2x + 5, p2y + 10) .release() -- 2.30.2