changeset 43908:4b3c8df189bc

rust-hg-path: implement more readable custom Debug for HgPath{,Buf} The default prints the vector of bytes as a list of integers. I considered instead getting rid of the Debug trait, but we use the Debug format in lots of derived Debug instances, so we probably do want to implement it. Differential Revision: https://phab.mercurial-scm.org/D7604
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 11 Dec 2019 09:39:14 -0800
parents 68af0228fedc
children dbaf9aabfb69
files rust/hg-core/src/utils/hg_path.rs
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/utils/hg_path.rs	Mon Dec 16 15:58:47 2019 -0800
+++ b/rust/hg-core/src/utils/hg_path.rs	Wed Dec 11 09:39:14 2019 -0800
@@ -77,7 +77,7 @@
 // `#[repr(transparent)]`.
 // Anyway, `Slice` representation and layout are considered implementation
 // detail, are not documented and must not be relied upon.
-#[derive(Eq, Ord, PartialEq, PartialOrd, Debug, Hash)]
+#[derive(Eq, Ord, PartialEq, PartialOrd, Hash)]
 pub struct HgPath {
     inner: [u8],
 }
@@ -181,13 +181,19 @@
     }
 }
 
+impl fmt::Debug for HgPath {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "HgPath({:?})", String::from_utf8_lossy(&self.inner))
+    }
+}
+
 impl fmt::Display for HgPath {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "{}", String::from_utf8_lossy(&self.inner))
     }
 }
 
-#[derive(Eq, Ord, Clone, PartialEq, PartialOrd, Debug, Hash)]
+#[derive(Eq, Ord, Clone, PartialEq, PartialOrd, Hash)]
 pub struct HgPathBuf {
     inner: Vec<u8>,
 }
@@ -210,6 +216,12 @@
     }
 }
 
+impl fmt::Debug for HgPathBuf {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "HgPathBuf({:?})", String::from_utf8_lossy(&self.inner))
+    }
+}
+
 impl fmt::Display for HgPathBuf {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "{}", String::from_utf8_lossy(&self.inner))