From 9bd8b04943f72b0781672a5ec2a26b9f76786d83 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 21 Nov 2020 12:47:26 +0000 Subject: [PATCH] zcoord: Better debug for LimbVal Signed-off-by: Ian Jackson --- zcoord/zcoord.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/zcoord/zcoord.rs b/zcoord/zcoord.rs index b0901092..7d8708c4 100644 --- a/zcoord/zcoord.rs +++ b/zcoord/zcoord.rs @@ -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] -- 2.30.2