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

login
register
mail settings
Submitter phabricator
Date Dec. 2, 2019, 2:20 p.m.
Message ID <d0bea621d84887d23bc9469db1972d82@localhost.localdomain>
Download mbox | patch
Permalink /patch/43564/
State Not Applicable
Headers show

Comments

phabricator - Dec. 2, 2019, 2:20 p.m.
Alphare marked an inline comment as done.
Alphare updated this revision to Diff 18421.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7523?vs=18399&id=18421

BRANCH
  default

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

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

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

CHANGE DETAILS




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, "{}", String::from_utf8_lossy(&self.inner))
+    }
+}
+
 #[derive(Eq, Ord, Clone, PartialEq, PartialOrd, Debug, Hash)]
 pub struct HgPathBuf {
     inner: Vec<u8>,
@@ -185,6 +192,12 @@ 
     }
 }
 
+impl fmt::Display for HgPathBuf {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "{}", String::from_utf8_lossy(&self.inner))
+    }
+}
+
 impl Deref for HgPathBuf {
     type Target = HgPath;