From 466cc71c6dd94bd1317d1d852be41228e796c161 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 12 Feb 2021 23:41:06 +0000 Subject: [PATCH] break out SimpleShape NFC Signed-off-by: Ian Jackson --- src/pieces.rs | 15 ++++++--------- src/spec.rs | 14 ++++++++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/pieces.rs b/src/pieces.rs index a5e5aa92..2bc59e80 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -140,15 +140,14 @@ impl Piece for SimpleShape { impl SimpleShape { #[throws(SpecError)] fn new(desc: Html, path: Html, - faces: &IndexVec, outline: Box, - spec_itemname: &Option, - def_itemname: &'_ str) + def_itemname: &'_ str, + common: &piece_specs::SimpleCommon) -> SimpleShape { - let itemname = spec_itemname.clone() + let itemname = common.itemname.clone() .unwrap_or_else(|| def_itemname.to_string()); - let colours = faces + let colours = common.faces .iter() .map(|s| s.try_into()) .collect::>()?; @@ -172,10 +171,9 @@ impl SimplePieceSpec for piece_specs::Disc { SimpleShape::new( Html::lit("disc"), svg_circle_path(self.diam as f64)?, - &self.faces, Box::new(outline), - &self.itemname, "simple-disc", + &self.common, )? } } @@ -204,10 +202,9 @@ impl SimplePieceSpec for piece_specs::Square { SimpleShape::new( Html::lit("square"), svg_rectangle_path(self.xy()?.promote())?, - &self.faces, Box::new(outline), - &self.itemname, "simple-square", + &self.common, )? } } diff --git a/src/spec.rs b/src/spec.rs index 59d55273..03bcccb2 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -195,17 +195,23 @@ pub mod piece_specs { pub type FaceColourSpecs = IndexVec; #[derive(Debug,Serialize,Deserialize)] - pub struct Disc { + pub struct SimpleCommon { pub itemname: Option, - pub diam: Coord, pub faces: IndexVec, } + #[derive(Debug,Serialize,Deserialize)] + pub struct Disc { + pub diam: Coord, + #[serde(flatten)] + pub common: SimpleCommon, + } + #[derive(Debug,Serialize,Deserialize)] pub struct Square { - pub itemname: Option, pub size: Vec, - pub faces: IndexVec, + #[serde(flatten)] + pub common: SimpleCommon, } /* pub struct Hand { -- 2.30.2