From: Ian Jackson Date: Sat, 21 Nov 2020 12:50:50 +0000 (+0000) Subject: zcoord: impls for LimbVal X-Git-Tag: otter-0.2.0~440 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=70a97f5b4bba4690c23a3bc56ae6b86c745374f2;p=otter.git zcoord: impls for LimbVal Signed-off-by: Ian Jackson --- diff --git a/zcoord/zcoord.rs b/zcoord/zcoord.rs index 7d8708c4..270459dc 100644 --- a/zcoord/zcoord.rs +++ b/zcoord/zcoord.rs @@ -139,9 +139,9 @@ impl From for LimbVal { const fn lv(raw: RawLimbVal) -> LimbVal { LimbVal(Wrapping(raw)) } impl LimbVal { - fn primitive(self) -> RawLimbVal { self.0.0 } + pub fn primitive(self) -> RawLimbVal { self.0.0 } /// return value is the top bits, shifted - fn to_str_buf(self, out: &mut [Tail1; DIGITS_PER_LIMB]) -> LimbVal { + pub fn to_str_buf(self, out: &mut [Tail1; DIGITS_PER_LIMB]) -> LimbVal { let mut l = self; for p in out.into_iter().rev() { let v = (l & DIGIT_MASK).primitive() as u8; @@ -152,24 +152,26 @@ impl LimbVal { } } -impl Debug for LimbVal { +impl Display 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())?; + 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()) +impl Debug for LimbVal { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { + write!(f, "lv(")?; + Display::fmt(self, f)?; + write!(f, ")")?; } -}*/ +} //---------- Mutabel ----------