chiark / gitweb /
Use serde rc support, duh
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 15 Jul 2020 22:29:25 +0000 (23:29 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 15 Jul 2020 22:29:25 +0000 (23:29 +0100)
Cargo.toml
src/api.rs
src/gamestate.rs
src/updates.rs

index 8814790dd71e8bdba2d2615f33fee6d90c51bd0c..272b873902c2c43e56e15d1768e3c66fc7ce730b 100644 (file)
@@ -21,7 +21,7 @@ rand = "0"
 #arrayvec = "0"
 
 #toml = "0.5"
-serde = { version = "1", features = ["derive"] }
+serde = { version = "1", features = ["derive","rc"] }
 serde_json = "1"
 
 htmlescape = "0.3"
index cd4c5246adaa4e34846be9d9a24a64ad28206f0c..282f33e47176cbfbd06a4d3871c1fc386fbd2f2d 100644 (file)
@@ -114,7 +114,7 @@ fn api_piece_op<O: ApiPieceOp>(form : Json<ApiPiece<O>>)
       });
 
       for logentry in logents {
-        let logentry = LogEntryRef(Arc::new(logentry));
+        let logentry = Arc::new(logentry);
         gs.log.push((gen, logentry.clone()));
         us.push(PreparedUpdateEntry::Log(logentry));
       }
index 8e176026175182fa2cb43b94516981646256a1d0..e147f25e44277a050c76f0d25023ef1f13edadd1 100644 (file)
@@ -62,8 +62,7 @@ pub struct PlayerState {
   pub nick : String,
 }
 
-#[derive(Debug,Clone)]
-pub struct LogEntryRef(pub Arc<LogEntry>);
+pub type LogEntryRef = Arc<LogEntry>;
 
 #[derive(Debug,Serialize,Deserialize)]
 pub struct LogEntry {
@@ -140,21 +139,6 @@ impl Display for ZCoord {
 
 // ---------- game state - rendering etc. ----------
 
-impl Serialize for LogEntryRef {
-  #[throws(S::Error)]
-  fn serialize<S:Serializer>(&self, s: S) -> S::Ok {
-    self.0.serialize(s)?
-  }
-}
-
-impl<'d> Deserialize<'d> for LogEntryRef {
-  #[throws(D::Error)]
-  fn deserialize<D:Deserializer<'d>>(d: D) -> LogEntryRef {
-    let l : LogEntry = <LogEntry as Deserialize<'_>>::deserialize(d)?;
-    LogEntryRef(Arc::new(l))
-  }
-}
-
 impl PieceState {
   #[throws(SE)]
   pub fn make_defs(&self, pri : &PieceRenderInstructions) -> String {
index c5678d8a09e689da0c69fd8acb07da4d616e5b9b..21b78bb9cbdd217a24a64a945e3788eeb65d1cc4 100644 (file)
@@ -103,7 +103,7 @@ impl PreparedUpdateEntry {
         op.new_state().map(|x| x.svg.len()).unwrap_or(0)
       },
       Log(logent) => {
-        logent.0.html.as_bytes().len() * 3
+        logent.html.as_bytes().len() * 3
       }
     }
   }
@@ -169,7 +169,7 @@ impl PreparedUpdate {
           TransmitUpdateEntry::Piece { piece, op }
         },
         PreparedUpdateEntry::Log(logent) => {
-          TransmitUpdateEntry::Log(&logent.0)
+          TransmitUpdateEntry::Log(&logent)
         },
       };
       ents.push(ue);