From: Ian Jackson Date: Sun, 15 Aug 2021 20:49:27 +0000 (+0100) Subject: slip: DumpHex prints utf8 debug output too X-Git-Tag: hippotat/1.0.0~163 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=488a06a5ddac13bec6ddaf5e02ebc937c1e3b805;p=hippotat.git slip: DumpHex prints utf8 debug output too Signed-off-by: Ian Jackson --- diff --git a/src/slip.rs b/src/slip.rs index b1d6eca..0b1fe6c 100644 --- a/src/slip.rs +++ b/src/slip.rs @@ -180,6 +180,12 @@ impl Debug for DumpHex<'_> { #[throws(fmt::Error)] fn fmt(&self, f: &mut fmt::Formatter) { for v in self.0 { write!(f, "{:02x}", v)?; } + match str::from_utf8(self.0) { + Ok(s) => write!(f, "={:?}", s)?, + Err(x) => write!(f, "={:?}..", + str::from_utf8(&self.0[0..x.valid_up_to()]).unwrap() + )?, + } } }