# HG changeset patch # User Raphaël Gomès # Date 1575044124 -3600 # 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 -r 5ac243a92e37 -r c27e688fcdc3 rust/hg-core/src/utils/hg_path.rs --- 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, @@ -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;