chiark / gitweb /
introduce PreparedUpdateEntry_Piece (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 24 Jan 2021 11:47:43 +0000 (11:47 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 28 Jan 2021 23:17:50 +0000 (23:17 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/updates.rs

index 26118a848f928e07d3931e21e045a5473c26ae10..ad96f5ab44a2ceb1429e8bc043a4f27b0bb2ac5c 100644 (file)
@@ -6,6 +6,9 @@
 
 use crate::imports::*;
 
+type PUE = PreparedUpdateEntry;
+#[allow(non_camel_case_types)] type PUE_P = PreparedUpdateEntry_Piece;
+
 // ---------- newtypes, type aliases, basic definitions ----------
 
 #[derive(Debug,Copy,Clone,Eq,PartialEq,Deserialize,Serialize)]
@@ -41,11 +44,7 @@ pub struct PreparedUpdate {
 
 #[derive(Debug)]
 pub enum PreparedUpdateEntry {
-  Piece {
-    by_client: IsResponseToClientOp,
-    piece: VisiblePieceId,
-    op: PieceUpdateOp<PreparedPieceState, ZLevel>,
-  },
+  Piece(PreparedUpdateEntry_Piece),
   SetTableSize(Pos),
   SetTableColour(Colour),
   SetLinks(Arc<LinksTable>),
@@ -62,6 +61,14 @@ pub enum PreparedUpdateEntry {
   Error (Option<ClientId> /* none: all */, ErrorSignaledViaUpdate),
 }
 
+#[allow(non_camel_case_types)]
+#[derive(Debug)]
+pub struct PreparedUpdateEntry_Piece {
+  by_client: IsResponseToClientOp,
+  piece: VisiblePieceId,
+  op: PieceUpdateOp<PreparedPieceState, ZLevel>,
+}
+
 #[derive(Debug,Clone,Serialize)]
 pub struct PreparedPieceState {
   pub pos: Pos,
@@ -206,7 +213,7 @@ impl PreparedUpdateEntry {
   pub fn json_len(&self) -> usize {
     use PreparedUpdateEntry::*;
     match self {
-      Piece { ref op, .. } => {
+      Piece(PUE_P { ref op, .. }) => {
         50 +
         op.new_state().map(|x| x.svg.0.as_bytes().len()).unwrap_or(0)
       }
@@ -375,7 +382,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
       piece, PieceUpdateOp::Modify(()), lens
     )?;
     let update = match update {
-      PreparedUpdateEntry::Piece {
+      PUE_P {
         piece,
         op: PieceUpdateOp::Modify(state),
         ..
@@ -397,7 +404,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
   #[throws(InternalError)]
   fn piece_update_fallible(&mut self, piece: PieceId,
                            update: PieceUpdateOp<(),()>,
-                           lens: &dyn Lens) -> PreparedUpdateEntry {
+                           lens: &dyn Lens) -> PreparedUpdateEntry_Piece {
     type WRC = WhatResponseToClientOp;
 
     let gen = self.gen();
@@ -440,7 +447,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
       }
     };
 
-    PreparedUpdateEntry::Piece {
+    PreparedUpdateEntry_Piece {
       piece,
       by_client : self.by_client,
       op : update,
@@ -453,6 +460,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
     // this point to back out a game state change.
 
     let update = self.piece_update_fallible(piece, update, lens)
+      .map(|update| PUE::Piece(update))
       .unwrap_or_else(|e| {
         error!("piece update error! piece={:?} lens={:?} error={:?}",
                piece, &lens, &e);
@@ -517,7 +525,7 @@ impl PreparedUpdate {
     for u in &self.us {
       trace!("for_transmit to={:?} {:?}", dest, &u);
       let ue = match u {
-        &PUE::Piece { piece, by_client, ref op } => {
+        &PUE::Piece(PUE_P { piece, by_client, ref op }) => {
           let ns = ||op.new_state();
           enum FTG<'u> {
             Recorded(ClientSequence, Option<&'u PreparedPieceState>),