From: Ian Jackson Date: Wed, 15 Jul 2020 22:40:28 +0000 (+0100) Subject: use typetag X-Git-Tag: otter-0.2.0~1318 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=071e6c41469ac469190fe2d700a1ab3fb8102325;p=otter.git use typetag --- diff --git a/src/gamestate.rs b/src/gamestate.rs index 6b35f1da..9aad9064 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -47,7 +47,6 @@ pub struct GameState { #[derive(Debug,Serialize,Deserialize)] pub struct PieceState { pub pos : Pos, - #[serde(with="self::piece_serde")] pub p : Box, pub face : FaceId, pub held : Option, @@ -72,6 +71,7 @@ pub struct LogEntry { type SE = SVGProcessingError; type SR = Result<(),SE>; +#[typetag::serde] pub trait Piece : Send + Debug { // #[throws] doesn't work here for some reason fn svg_piece(&self, f: &mut String, pri: &PieceRenderInstructions) -> SR; @@ -177,21 +177,6 @@ impl PieceState { } } -// ---------- pice load and save ---------- - -mod piece_serde { - use crate::gamestate::*; - use serde::Serializer; - #[throws(S::Error)] - pub fn serialize(pc : &Box, s:S) -> S::Ok { - s.serialize_none()? - } - #[throws(D::Error)] - pub fn deserialize<'d,D:Deserializer<'d>>(d:D) -> Box { - panic!(); - } -} - // ========== ad-hoc and temporary ========== pub fn make_pieceid_visible(p : PieceId) -> VisiblePieceId { diff --git a/src/pieces.rs b/src/pieces.rs index e35ca68c..12f6fb5b 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -78,6 +78,7 @@ eprintln!("rescaled by {}: {} as {}",scale,&input,&out); out } +#[typetag::serde] impl Piece for SimpleShape { #[throws(SE)] fn svg_piece(&self, f: &mut String, pri: &PieceRenderInstructions) {