chiark
/
gitweb
/
~ian
/
hippotat.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
2b98afc
)
slip: DumpHex prints utf8 debug output too
author
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 15 Aug 2021 20:49:27 +0000
(21:49 +0100)
committer
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 15 Aug 2021 20:49:27 +0000
(21:49 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/slip.rs
patch
|
blob
|
history
diff --git
a/src/slip.rs
b/src/slip.rs
index b1d6eca91d53c5d8b2324d2723be8fa9b58f88bd..0b1fe6c93574e6de350fa2e99184fd24ad494d06 100644
(file)
--- 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()
+ )?,
+ }
}
}