From: Ian Jackson Date: Wed, 15 Jul 2020 22:29:25 +0000 (+0100) Subject: Use serde rc support, duh X-Git-Tag: otter-0.2.0~1321 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=162b7d9305322d316ae2f8b41dcca1da05e32d02;p=otter.git Use serde rc support, duh --- diff --git a/Cargo.toml b/Cargo.toml index 8814790d..272b8739 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/api.rs b/src/api.rs index cd4c5246..282f33e4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -114,7 +114,7 @@ fn api_piece_op(form : Json>) }); 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)); } diff --git a/src/gamestate.rs b/src/gamestate.rs index 8e176026..e147f25e 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -62,8 +62,7 @@ pub struct PlayerState { pub nick : String, } -#[derive(Debug,Clone)] -pub struct LogEntryRef(pub Arc); +pub type LogEntryRef = Arc; #[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(&self, s: S) -> S::Ok { - self.0.serialize(s)? - } -} - -impl<'d> Deserialize<'d> for LogEntryRef { - #[throws(D::Error)] - fn deserialize>(d: D) -> LogEntryRef { - let l : LogEntry = >::deserialize(d)?; - LogEntryRef(Arc::new(l)) - } -} - impl PieceState { #[throws(SE)] pub fn make_defs(&self, pri : &PieceRenderInstructions) -> String { diff --git a/src/updates.rs b/src/updates.rs index c5678d8a..21b78bb9 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -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);