Patchwork D7604: rust-hg-path: implement more readable custom Debug for HgPath{, Buf}

login
register
mail settings
Submitter phabricator
Date Dec. 11, 2019, 5:51 p.m.
Message ID <differential-rev-PHID-DREV-amihcphfvv6yf4rcaft6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43721/
State Superseded
Headers show

Comments

phabricator - Dec. 11, 2019, 5:51 p.m.
martinvonz created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7604

AFFECTED FILES
  rust/hg-core/src/utils/hg_path.rs

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel
phabricator - Dec. 11, 2019, 5:57 p.m.
kevincox added inline comments.
kevincox accepted this revision.

INLINE COMMENTS

> hg_path.rs:186
> +    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> +        write!(f, "HgPath({})", String::from_utf8_lossy(&self.inner))
> +    }

I would recommend `"HgPath({:?})"` so that the result is unambiguous and nicely escaped.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7604/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7604

To: martinvonz, #hg-reviewers, kevincox
Cc: durin42, kevincox, mercurial-devel
phabricator - Dec. 11, 2019, 6:05 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> kevincox wrote in hg_path.rs:186
> I would recommend `"HgPath({:?})"` so that the result is unambiguous and nicely escaped.

Good point.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7604/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7604

To: martinvonz, #hg-reviewers, kevincox
Cc: durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-core/src/utils/hg_path.rs b/rust/hg-core/src/utils/hg_path.rs
--- a/rust/hg-core/src/utils/hg_path.rs
+++ b/rust/hg-core/src/utils/hg_path.rs
@@ -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))