chiark / gitweb /
Introduce OpOutcomeThunkGeneric resolve on Result
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 10:08:59 +0000 (11:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 10:10:57 +0000 (11:10 +0100)
On the way to getting rid of the other ad-hoc resolution site.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/prelude.rs
src/updates.rs

index a0ed7c8d14c36ac84e04115358361288e015380a..0d3c05eddfc1063f148c54a947552fe80ac2678f 100644 (file)
@@ -196,11 +196,7 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
       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 {
index 5a1cf43bd71b6213c287f520f6d489f868372db3..a669c99c3140f489e2781ce59e3724327d3e6a57 100644 (file)
@@ -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<NS,ZL> = PieceUpdateOp<NS,ZL>;
index 725a25d8162822cff9ea925416cc654b191ac9c9..b49740574c51b50dec45b950c225a33d9f882637 100644 (file)
@@ -380,6 +380,17 @@ impl StableIndexOffset for UpdateId {
   fn zero() -> Self { UpdateId(0) }
 }
 
+#[ext(pub)]
+impl<A,T,E> Result<OpOutcomeThunkGeneric<A,T,E>,E> {
+  fn resolve(self, ig: &mut InstanceGuard, args: A) -> Result<T,E> {
+    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 {