chiark / gitweb /
zcoord: Better debug for LimbVal
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Nov 2020 12:47:26 +0000 (12:47 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Nov 2020 12:47:26 +0000 (12:47 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
zcoord/zcoord.rs

index b09010926f2a0fe93113e2d23ad5223f983b7780..7d8708c4ed51b5783d6a3e76c009174e0ab5c8f3 100644 (file)
@@ -153,10 +153,23 @@ impl LimbVal {
 }
 
 impl Debug for LimbVal {
+  #[throws(fmt::Error)]
+  fn fmt(&self, f: &mut fmt::Formatter) {
+    let mut buf = [0u8; DIGITS_PER_LIMB];
+    let lhs : RawLimbVal = self.to_str_buf(&mut buf).primitive();
+    write!(f, "lv(")?;
+    if lhs != 0 {
+      write!(f, "{:#x?}!", lhs)?;
+    }
+    write!(f, "{})", str::from_utf8(&buf).unwrap())?;
+  }
+}
+
+/*impl Debug for LimbVal {
   fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error> {
     write!(f, "lv({:#x?})", self.primitive())
   }
-}
+}*/
 
 //---------- Mutabel ----------
 
@@ -769,7 +782,7 @@ mod test {
   fn limb_debug() {
     let l : LimbVal = 0x42.into();
     assert_eq!( &format!("{:?}", &l),
-                "lv(0x42)" );
+                "lv(0000000022)" );
   }
 
   #[test]