From: Ian Jackson Date: Sun, 1 May 2022 10:03:10 +0000 (+0100) Subject: Genericise OpOutcomeThunk X-Git-Tag: otter-1.1.0~379 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a6be48cc72b15a8b0ad799fee8b6b2d03a1c7353;p=otter.git Genericise OpOutcomeThunk So that we can centralise resolution. Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index eda86336..a0ed7c8d 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -145,7 +145,7 @@ fn api_piece_op(form: Json>) })().and_then(|(thunk, loose_conflict)| Ok(( match thunk { OpOutcomeThunk::Immediate(r) => r, - OpOutcomeThunk::Reborrow(f) => f(&mut ig, player, piece)?, + OpOutcomeThunk::Reborrow(f) => f(&mut ig, (player, piece))?, }, loose_conflict ))) { Err(APOE::Inapplicable(poe)) => { @@ -199,7 +199,7 @@ fn api_piece_op(form: Json>) let unprepared = match thunk { Err(e) => Err(e), Ok(OpHookThunk::Immediate(uu)) => Ok(uu), - Ok(OpHookThunk::Reborrow(f)) => f(&mut ig, player), + Ok(OpHookThunk::Reborrow(f)) => f(&mut ig, (player,)), }; if let Ok(unprepared) = unprepared.map_err( |e| error!("internal error on change hook: {:?}", e)); diff --git a/src/currency.rs b/src/currency.rs index b57e21b2..44c54dfe 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -127,7 +127,7 @@ impl PieceTrait for Banknote { take: MultigrabQty, new_z: ShouldSetZLevel) -> OpOutcomeThunk { let currency = self.currency.clone(); OpOutcomeThunk::Reborrow(Box::new( - move |ig: &mut InstanceGuard, player: PlayerId, tpiece: PieceId| + move |ig: &mut InstanceGuard, (player, tpiece)| { ig.fastsplit_split(player, tpiece, show, new_z, move |_: &IOccults, _: &GameOccults, gpl: &GPlayer, diff --git a/src/updates.rs b/src/updates.rs index 9e4cdb63..725a25d8 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -165,38 +165,28 @@ pub enum PieceUpdateOp { SetZLevelQuiet(ZL), } -#[derive(From)] -pub enum OpOutcomeThunk { - Immediate(UpdateFromOpComplex), - /// Allows a UI operation full mutable access to the whole Instance. - /// - /// Use with care! Eg, you might have to call save_game_and_aux_later. - /// - /// Adding and removing pieces during play (rather than management) - /// is complicated, because we want to avoid having to rewrite the aux. - /// file during routine game saves. `fastsplit.rs` has machinery that - /// can achieve this. - Reborrow(Box Result>), -} - #[derive(From,Educe)] -#[educe(Default)] -pub enum OpHookThunk { +#[educe(Default(bound="T: Default"))] +pub enum OpOutcomeThunkGeneric { #[educe(Default)] - Immediate(UnpreparedUpdates), - /// Allows a UI operation full mutable access to the whole Instance. + Immediate(T), + /// Allows an operation full mutable access to the whole Instance. /// - /// Use with care! Eg, you might have to call save_game_and_aux_late.r + /// Use with care! Eg, you might have to call save_game_and_aux_later. /// /// Adding and removing pieces during play (rather than management) /// is complicated, because we want to avoid having to rewrite the aux. /// file during routine game saves. `fastsplit.rs` has machinery that /// can achieve this. - Reborrow(Box Result>), + Reborrow(Box Result>), } +pub type OpOutcomeThunk = OpOutcomeThunkGeneric< + (PlayerId, PieceId), UpdateFromOpComplex, ApiPieceOpError>; + +pub type OpHookThunk = OpOutcomeThunkGeneric< + (PlayerId,), UnpreparedUpdates, InternalError>; + pub type UpdateFromOpComplex = ( PieceUpdate, UnpreparedUpdates,