From: Ian Jackson Date: Sun, 12 Jul 2020 15:10:49 +0000 (+0100) Subject: change api of svg_x_defs X-Git-Tag: otter-0.2.0~1352 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5ef85352ed0c533570b1e3d9022732f7cb6474ce;p=otter.git change api of svg_x_defs --- 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 {