chiark / gitweb /
VerticesPrint main
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Oct 2022 21:43:08 +0000 (22:43 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Oct 2022 21:43:08 +0000 (22:43 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/lib.rs

index 06566d826eae6617b597ed08355daf757fdca64c..7fbc6020b3cc6eed771806dfd49d4396cac0efe6 100644 (file)
@@ -90,16 +90,23 @@ pub fn shape_all_rotations(shape: &Shape)
   })
 }
 
-pub fn print_shape(shape: &Shape) -> io::Result<()> {
-  let mut o = io::stdout().lock();
-  for vx in shape {
-    for c in vx {
-      write!(o, "{}", c)?;
+pub struct VerticesPrint<'s>(pub &'s Shape);
+
+impl Display for VerticesPrint<'_> {
+  fn fmt(&self, o: &mut fmt::Formatter) -> fmt::Result {
+    for vx in self.0 {
+      for c in vx {
+        write!(o, "{}", c)?;
+      }
+      write!(o, ",")?;
     }
-    write!(o, ",")?;
+    Ok(())
   }
-  write!(o, "\n")?;
-  Ok(())
+}
+
+pub fn print_shape(shape: &Shape) -> io::Result<()> {
+  let mut o = io::stdout().lock();
+  writeln!(o, "{}", VerticesPrint(shape))
 }
 
 pub struct Xyzzy<'s>(pub &'s Shape);