repo_path: make Debug formatting of RepoPathComponent less verbose

Since RepoPath is formatted as a string, it should be okay for RepoPathComponent
to do the same.
This commit is contained in:
Yuya Nishihara 2024-04-06 00:44:27 +09:00
parent 1134dc159e
commit f3485c9efb

View file

@ -28,7 +28,7 @@ use crate::content_hash::ContentHash;
use crate::file_util;
/// Owned `RepoPath` component.
#[derive(ContentHash, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[derive(ContentHash, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RepoPathComponentBuf {
// Don't add more fields. Eq, Hash, and Ord must be compatible with the
// borrowed RepoPathComponent type.
@ -36,7 +36,7 @@ pub struct RepoPathComponentBuf {
}
/// Borrowed `RepoPath` component.
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Hash, RefCastCustom)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, RefCastCustom)]
#[repr(transparent)]
pub struct RepoPathComponent {
value: str,
@ -59,6 +59,18 @@ impl RepoPathComponent {
}
}
impl Debug for RepoPathComponent {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", &self.value)
}
}
impl Debug for RepoPathComponentBuf {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
<RepoPathComponent as Debug>::fmt(self, f)
}
}
impl From<&str> for RepoPathComponentBuf {
fn from(value: &str) -> Self {
RepoPathComponentBuf::from(value.to_owned())