From 659589c35d6bde27479d72b9c7ea81bc5d33c618 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 1 May 2022 11:08:59 +0100 Subject: [PATCH] Introduce OpOutcomeThunkGeneric resolve on Result On the way to getting rid of the other ad-hoc resolution site. Signed-off-by: Ian Jackson --- daemon/api.rs | 6 +----- src/prelude.rs | 1 + src/updates.rs | 11 +++++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index a0ed7c8d..0d3c05ed 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -196,11 +196,7 @@ fn api_piece_op(form: Json>) piece, was_held, ); - let unprepared = match thunk { - Err(e) => Err(e), - Ok(OpHookThunk::Immediate(uu)) => Ok(uu), - Ok(OpHookThunk::Reborrow(f)) => f(&mut ig, (player,)), - }; + let unprepared = thunk.resolve(&mut ig, (player,)); if let Ok(unprepared) = unprepared.map_err( |e| error!("internal error on change hook: {:?}", e)); then { diff --git a/src/prelude.rs b/src/prelude.rs index 5a1cf43b..a669c99c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -236,6 +236,7 @@ pub type IOI = IOccultIlk; pub use PriOccultedGeneral as PriOG; // updates.rs +pub use OpOutcomeThunkGeneric as OOTG; pub type PUE = PreparedUpdateEntry; pub type PUFOS = PieceUpdateFromOpSimple; pub type PUO = PieceUpdateOp; diff --git a/src/updates.rs b/src/updates.rs index 725a25d8..b4974057 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -380,6 +380,17 @@ impl StableIndexOffset for UpdateId { fn zero() -> Self { UpdateId(0) } } +#[ext(pub)] +impl Result,E> { + fn resolve(self, ig: &mut InstanceGuard, args: A) -> Result { + match self { + Err(e) => Err(e), + Ok(OOTG::Immediate(uu)) => Ok(uu), + Ok(OOTG::Reborrow(f)) => f(ig, args), + } + } +} + // ---------- prepared updates, queued in memory ---------- pub struct PlayerUpdatesStartContext { -- 2.30.2