From 092ee1d08c437858c38b747a16c5d78d6ebd781b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 1 May 2022 12:59:01 +0100 Subject: [PATCH] ToRecalculate: Refactor implement methods These are more convenient now, and the authorisation trickery is now where we can more clearly justify it. Acked-by: Ian Jackson --- daemon/api.rs | 8 +------- daemon/cmdlistener.rs | 8 +------- src/hidden.rs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index 956081d3..c8a79d0d 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -205,13 +205,7 @@ fn api_piece_op(form: Json>) 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); diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 32aab755..e8c8b5ca 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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) }) }); diff --git a/src/hidden.rs b/src/hidden.rs index 283164f9..d47a41c9 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -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(self, igu: &mut Unauthorised) + -> 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, -- 2.30.2