chiark / gitweb /
at-currency: Make move_money a method on Session
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 May 2022 12:23:33 +0000 (13:23 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 May 2022 12:23:33 +0000 (13:23 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/at-currency.rs

index 2b63264aa600d82d8bce8ed441c31be76bf78cff..fcb7da4fa68ab0d1c28e7f4ea58371a8ac6349ee 100644 (file)
@@ -6,15 +6,17 @@ use crate::*;
 
 type Ctx = UsualCtx;
 
-#[throws(Explode)]
-fn move_money<PI:Idx>(alice: &mut Session,
-                      a_pieces: &mut Pieces<PI>, piece: PI,
-                      qty: i32, z: &str, pos: Pos) {
-  alice.api_piece_op_single(PuSynch((&mut *a_pieces, piece)).id(), (
-    "multigrab", json!({ "n": qty, 'z': z })
-  ))?;
-
-  alice.api_piece(GH::Ungrab, PuSynch((&mut *a_pieces, piece)), pos)?;
+impl Session {
+  #[throws(Explode)]
+  fn move_money<PI:Idx>(&mut self,
+                        a_pieces: &mut Pieces<PI>, piece: PI,
+                        qty: i32, z: &str, pos: Pos) {
+    self.api_piece_op_single(PuSynch((&mut *a_pieces, piece)).id(), (
+      "multigrab", json!({ "n": qty, 'z': z })
+    ))?;
+
+    self.api_piece(GH::Ungrab, PuSynch((&mut *a_pieces, piece)), pos)?;
+  }
 }
 
 impl Ctx {
@@ -79,7 +81,7 @@ impl Ctx {
 
     let bank = a_pieces.find_by_desc_glob("*400ƒ*");
 
-    move_money(&mut alice, &mut a_pieces, bank, 399, "u000000000", hand_pos)?;
+    alice.move_money(&mut a_pieces, bank, 399, "u000000000", hand_pos)?;
     alice.synchu(&mut a_pieces)?;
     
     let _ = &mut bob;