chiark / gitweb /
at: impl PieceSpecForOp for &mut too
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 14 Mar 2021 17:03:12 +0000 (17:03 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 14 Mar 2021 17:05:47 +0000 (17:05 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/at-otter.rs

index bf5d2033d105ab1e5bcc42e1b0a7580ff6eccd00..4fd4866a44c684389c74c2e4f9d962cbac1338ca 100644 (file)
@@ -438,27 +438,35 @@ impl PieceSpecForOp for &String {
 }
 
 type PuUp<'pcs, PI> = (&'pcs mut Pieces<PI>, PI);
-impl<PI:Idx> PieceSpecForOp for PuUp<'_, PI> {
-  type PI = PI;
-  fn id(&self) -> &str { &self.0[self.1].id }
-  fn for_update(&mut self) -> Option<&mut PieceInfo<JsV>> {
-    Some(&mut self.0[self.1])
-  }
-}
-
 #[derive(Debug)]
 /// Synchronise after op but before any ungrab.
 pub struct PuSynch<T>(T);
-impl<PI:Idx> PieceSpecForOp for PuSynch<PuUp<'_,PI>> {
-  type PI = PI;
-  fn id(&self) -> &str { self.0.id() }
-  fn for_update(&mut self) -> Option<&mut PieceInfo<JsV>> {
-    self.0.for_update()
-  }
-  fn for_synch(&mut self) -> Option<&mut Pieces<PI>> {
-    Some(self.0.0)
+
+macro_rules! impl_PieceSpecForOp {
+  ($($amp:tt $mut:tt)?) => {
+
+    impl<PI:Idx> PieceSpecForOp for $($amp $mut)? PuUp<'_, PI> {
+      type PI = PI;
+      fn id(&self) -> &str { &self.0[self.1].id }
+      fn for_update(&mut self) -> Option<&mut PieceInfo<JsV>> {
+        Some(&mut self.0[self.1])
+      }
+    }
+
+    impl<PI:Idx> PieceSpecForOp for PuSynch<$($amp $mut)? PuUp<'_,PI>> {
+      type PI = PI;
+      fn id(&self) -> &str { self.0.id() }
+      fn for_update(&mut self) -> Option<&mut PieceInfo<JsV>> {
+        self.0.for_update()
+      }
+      fn for_synch(&mut self) -> Option<&mut Pieces<PI>> {
+        Some(self.0.0)
+      }
+    }
   }
 }
+impl_PieceSpecForOp!{}
+impl_PieceSpecForOp!{&mut}
 
 #[derive(Debug,Copy,Clone)]
 pub enum GrabHow { Raw, Grab, Ungrab, With }