From 5ef85352ed0c533570b1e3d9022732f7cb6474ce Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 12 Jul 2020 16:10:49 +0100 Subject: [PATCH] change api of svg_x_defs --- src/gamestate.rs | 9 +++++++-- src/pieces.rs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gamestate.rs b/src/gamestate.rs index 40294eb9..8aed7d08 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -68,12 +68,17 @@ type SE = SVGProcessingError; type SR = Result<(),SE>; pub trait Piece : Send + Debug { + // #[throws] doesn't work here for some reason fn svg_piece(&self, f: &mut String, pri: &PieceRenderInstructions) -> SR; + #[throws(SE)] fn outline_path(&self, pri : &PieceRenderInstructions) -> String; + #[throws(SE)] fn surround_path(&self, pri : &PieceRenderInstructions) -> String; - fn svg_x_defs(&self, pri : &PieceRenderInstructions) -> String; + + fn svg_x_defs(&self, f: &mut String, pri : &PieceRenderInstructions) -> SR; + #[throws(SE)] fn thresh_dragraise(&self, pri : &PieceRenderInstructions) -> Option; @@ -143,7 +148,7 @@ impl PieceState { write!(defs, r##""##, pri.id, pr.p.surround_path(&pri)?)?; - write!(defs, "{}", pr.p.svg_x_defs(&pri))?; + pr.p.svg_x_defs(&mut defs, &pri)?; defs } diff --git a/src/pieces.rs b/src/pieces.rs index a595b567..c679e8a6 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -101,8 +101,8 @@ impl Piece for SimpleShape { -> Option { Some(self.approx_dia / 2) } - fn svg_x_defs(&self, _pri : &PieceRenderInstructions) -> String { - "".to_owned() + #[throws(SE)] + fn svg_x_defs(&self, _f: &mut String, _pri : &PieceRenderInstructions) { } #[throws(SE)] fn describe_html(&self, face : Option) -> String { -- 2.30.2