Patchwork D7523: rust-hg-path: implement `Display` for `HgPath` and `HgPathBuf`

login
register
mail settings
Submitter phabricator
Date Nov. 29, 2019, 5:56 p.m.
Message ID <differential-rev-PHID-DREV-b4arsfry2xr2lj4kaajf-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43529/
State Superseded
Headers show

Comments

phabricator - Nov. 29, 2019, 5:56 p.m.
Alphare created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is useful when debugging, to get a human readable output instead of an
  array of `u8`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel
phabricator - Dec. 2, 2019, 1:04 p.m.
This revision now requires changes to proceed.
kevincox added inline comments.
kevincox requested changes to this revision.

INLINE COMMENTS

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

This looks more like a `Debug` format than a `Display` format. For `Display I would just do `write!(f, "{}", String::from_utf8_lossy(&self.inner))`

REPOSITORY
  rHG Mercurial

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

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

To: Alphare, #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
@@ -7,6 +7,7 @@ 
 
 use std::borrow::Borrow;
 use std::ffi::{OsStr, OsString};
+use std::fmt;
 use std::ops::Deref;
 use std::path::{Path, PathBuf};
 
@@ -162,6 +163,12 @@ 
     }
 }
 
+impl fmt::Display for HgPath {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "HgPath {{ {} }}", String::from_utf8_lossy(&self.inner))
+    }
+}
+
 #[derive(Eq, Ord, Clone, PartialEq, PartialOrd, Debug, Hash)]
 pub struct HgPathBuf {
     inner: Vec<u8>,
@@ -185,6 +192,16 @@ 
     }
 }
 
+impl fmt::Display for HgPathBuf {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(
+            f,
+            "HgPathBuf {{ {} }}",
+            String::from_utf8_lossy(&self.inner)
+        )
+    }
+}
+
 impl Deref for HgPathBuf {
     type Target = HgPath;