Mercurial > hg
changeset 43827:c27e688fcdc3
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
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Fri, 29 Nov 2019 17:15:24 +0100 |
parents | 5ac243a92e37 |
children | 36444dddaeb4 |
files | rust/hg-core/src/utils/hg_path.rs |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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;