rust-hg-path: implement `Display` for `HgPath` and `HgPathBuf`
This is useful when debugging, to get a human readable output instead of an
array of `u8`.
Differential Revision: https://phab.mercurial-scm.org/D7523
--- a/rust/hg-core/src/utils/hg_path.rs Mon Oct 14 13:57:30 2019 +0200
+++ b/rust/hg-core/src/utils/hg_path.rs Fri Nov 29 17:15:24 2019 +0100
@@ -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;