chiark / gitweb /
wdt: new move_pos extension method
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 28 Jan 2021 17:05:06 +0000 (17:05 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 28 Jan 2021 17:58:12 +0000 (17:58 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
wdriver.rs
wdriver/wdt-simple.rs

index cdcdf55f6cdfa54e6b781e7e3839771f2abff090..31d948a8b74f1537f53de59d9706e6b7d630600d 100644 (file)
@@ -893,6 +893,14 @@ impl<'g> PieceElement<'g> {
   }
 }
 
+impl<'g> TryInto<WebPos> 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<WebPos> for Pos {
 pub trait ActionChainExt: Sized {
   fn w_move<'g, P: IntoInWindow<WebPos>>
     (self, w: &'g WindowGuard, pos: P) -> Result<Self,AE>;
+
+  fn move_pos<'g, P: TryInto<WebPos, Error=AE>>
+    (self, pos: P) -> Result<Self,AE>;
 }
 
 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<WebPos, Error=AE>> (self, pos: P) -> Self {
+    let (px,py) = pos.try_into()?;
+    self.move_to(px,py)
+  }
 }
 
 impl Drop for Setup {
index 66e39e1fd3257b524047fc47b70d1170b09891e5..4425d18d5acb7dd11ed9ec65c3d628d55cb150f9 100644 (file)
@@ -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()