# HG changeset patch # User Raphaël Gomès # Date 2019-11-29 16:15:24 # Node ID c27e688fcdc375690929447e37901a4765ea3de4 # Parent 5ac243a92e374c51ba0d602e1eb1f065ca62c3c6 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 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 HgPath { } } +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, @@ -185,6 +192,12 @@ impl HgPathBuf { } } +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;