chiark / gitweb /
change api of svg_x_defs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jul 2020 15:10:49 +0000 (16:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jul 2020 15:10:49 +0000 (16:10 +0100)
src/gamestate.rs
src/pieces.rs

index 40294eb93198b36d0507f2f044d212e2f2a89612..8aed7d083d0ffe181baf23676851da82023ccea1 100644 (file)
@@ -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<Coord>;
@@ -143,7 +148,7 @@ impl PieceState {
     write!(defs,
            r##"<path id="select{}" stroke="black" fill="none" d="{}"/>"##,
            pri.id, pr.p.surround_path(&pri)?)?;
-    write!(defs, "{}", pr.p.svg_x_defs(&pri))?;
+    pr.p.svg_x_defs(&mut defs, &pri)?;
     defs
   }
 
index a595b56762b1b6e45ba6fec49484e293ae7536ed..c679e8a6bb8ed532f6e7c91f78176dd8d792501d 100644 (file)
@@ -101,8 +101,8 @@ impl Piece for SimpleShape {
                       -> Option<Coord> {
     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<FaceId>) -> String {