D7523: rust-hg-path: implement `Display` for `HgPath` and `HgPathBuf`
Alphare (Raphaël Gomès)
phabricator at mercurial-scm.org
Fri Nov 29 17:56:53 UTC 2019
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
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;
To: Alphare, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel
More information about the Mercurial-devel
mailing list