From: Ian Jackson Date: Mon, 13 Jul 2020 23:27:03 +0000 (+0100) Subject: wip serde for gamestate X-Git-Tag: otter-0.2.0~1324 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5688fd79fc94d0f573ebe7f0c8ea8188069a8bc0;p=otter.git wip serde for gamestate --- diff --git a/src/gamestate.rs b/src/gamestate.rs index 20204ffc..0d9ed257 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -38,7 +38,7 @@ pub struct ZLevel { // ---------- game state ---------- -#[derive(Debug,Serialize)] +#[derive(Debug,Serialize,Deserialize)] pub struct GameState { pub pieces : DenseSlotMap, pub players : DenseSlotMap, @@ -46,7 +46,7 @@ pub struct GameState { pub log : Vec<(Generation,LogEntryRef)>, } -#[derive(Debug,Serialize)] +#[derive(Debug,Serialize,Deserialize)] pub struct PieceState { pub pos : Pos, #[serde(with="self::piece_serde")] @@ -59,7 +59,7 @@ pub struct PieceState { pub gen_before_lastclient : Generation, } -#[derive(Debug,Serialize)] +#[derive(Debug,Serialize,Deserialize)] pub struct PlayerState { pub nick : String, } @@ -67,7 +67,7 @@ pub struct PlayerState { #[derive(Debug,Clone)] pub struct LogEntryRef(pub Arc); -#[derive(Debug,Serialize)] +#[derive(Debug,Serialize,Deserialize)] pub struct LogEntry { pub html : String, } @@ -148,6 +148,17 @@ impl Serialize for LogEntryRef { } } +impl<'d> Deserialize<'d> for LogEntryRef { + fn deserialize(d: D) -> Result where D: Deserializer<'d> { + todo!() + } + /* + fn deserialize(o:D) Result` + fn deserialize(&self, s: S) -> Result<::Ok, ::Error> where S: Serializer { + self.0.serialize(s) + }*/ +} + impl PieceState { #[throws(SE)] pub fn make_defs(&self, pri : &PieceRenderInstructions) -> String { @@ -197,7 +208,10 @@ mod piece_serde { pub fn serialize(pc : &Box, s:S) -> S::Ok { s.serialize_none()? } - pub fn deserialize() { } + #[throws(D::Error)] + pub fn deserialize<'d,D:Deserializer<'d>>(d:D) -> Box { + panic!(); + } } // ========== ad-hoc and temporary ========== diff --git a/src/imports.rs b/src/imports.rs index 35906b4c..d9117df9 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -25,7 +25,7 @@ pub use fehler::{throws,throw}; pub use serde::Deserialize; pub use serde::Serialize; -pub use serde::Serializer; +pub use serde::{Serializer,Deserializer}; pub use rocket_contrib::helmet::*; pub use rocket_contrib::templates::Template;