chiark / gitweb /
ToRecalculate: Refactor implement methods
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 11:59:01 +0000 (12:59 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 12:02:59 +0000 (13:02 +0100)
These are more convenient now, and the authorisation trickery is
now where we can more clearly justify it.

Acked-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/cmdlistener.rs
src/hidden.rs

index 956081d3b3ff077253d7050ef3560c1563d251c8..c8a79d0de40eee81b893b7caa7bcc5cef9384bef 100644 (file)
@@ -205,13 +205,7 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
       Ok::<(),Fatal>(())
     })();
 
-    let g = &mut *ig;
-    let gs = &mut g.gs;
-
-    (r, to_recalculate.implement(&mut gs.players,
-                             &mut gs.pieces,
-                             &mut gs.occults,
-                             &g.ipieces))
+    (r, to_recalculate.implement(&mut ig))
   });
 
   PrepareUpdatesBuffer::only_unprepared(&mut ig, unprepared_outer);
index 32aab755356fce6ab397a9b78d57527dc0dc6fa8..e8c8b5ca6dd3304b5da7164387721ffb623a2bb7 100644 (file)
@@ -1333,13 +1333,7 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>(
 
     })();
     (r, {
-      let ig = igu.by_mut(Authorisation::promise_any());
-      let g = &mut **ig;
-      let gs = &mut g.gs;
-      to_permute.implement(&mut gs.players,
-                           &mut gs.pieces,
-                           &mut gs.occults,
-                           &g.ipieces)
+      to_permute.implement_auth(&mut *igu)
     })
   });
 
index 283164f903ae0aac6c31131784cdb5597d9a5fcc..d47a41c92bbb9f2165d55c54111f2a9547030c3a 100644 (file)
@@ -850,7 +850,20 @@ mod recompute {
       (r, uu)
     }
     pub fn mark_dirty(&mut self, occid: OccId) { self.outdated.insert(occid); }
-    pub fn implement(self,
+
+    pub fn implement_auth<A>(self, igu: &mut Unauthorised<InstanceGuard,A>)
+                             -> Implemented {
+      // Caller must have had some kind of authorisation to do whatever
+      // it was they did.  It doesn't amke sense to demand any more.
+      self.implement(igu.by_mut(Authorisation::promise_any()))
+    }
+    pub fn implement(self, ig: &mut Instance) -> Implemented {
+      self.implement_inner(&mut ig.gs.players,
+                           &mut ig.gs.pieces,
+                           &mut ig.gs.occults,
+                           &ig.ipieces)
+    }
+    fn implement_inner(self,
                      gplayers: &mut GPlayers,
                      gpieces: &mut GPieces,
                      goccults: &mut GOccults,