From c5b318700235113fc687dcf9b201d64e775fc9d6 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 1 May 2024 11:20:07 +0000 Subject: feat(tvix/castore/path): implement Debug + Display We implement Debug explicitly, so that we don't just see raw integers. Change-Id: I11213094728f3e0c674562ee71c092a950041632 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11565 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/castore/src/path.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'tvix/castore/src/path.rs') diff --git a/tvix/castore/src/path.rs b/tvix/castore/src/path.rs index 8cca5b62f8..3577ea80a4 100644 --- a/tvix/castore/src/path.rs +++ b/tvix/castore/src/path.rs @@ -1,13 +1,19 @@ //! Contains data structures to deal with Paths in the tvix-castore model. -use std::{borrow::Borrow, mem, ops::Deref, str::FromStr}; +use std::{ + borrow::Borrow, + fmt::{self, Debug, Display}, + mem, + ops::Deref, + str::FromStr, +}; use bstr::ByteSlice; /// Represents a Path in the castore model. /// These are always relative, and platform-independent, which distinguishes /// them from the ones provided in the standard library. -#[derive(Debug, Eq, Hash, PartialEq)] +#[derive(Eq, Hash, PartialEq)] #[repr(transparent)] // SAFETY: Representation has to match [u8] pub struct Path { // As node names in the castore model cannot contain slashes, @@ -86,10 +92,22 @@ impl Path { } } +impl Debug for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Debug::fmt(self.inner.as_bstr(), f) + } +} + +impl Display for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(self.inner.as_bstr(), f) + } +} + /// Represents a owned PathBuf in the castore model. /// These are always relative, and platform-independent, which distinguishes /// them from the ones provided in the standard library. -#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)] +#[derive(Clone, Default, Eq, Hash, PartialEq)] pub struct PathBuf { inner: Vec, } @@ -135,6 +153,18 @@ impl FromStr for PathBuf { } } +impl Debug for PathBuf { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Debug::fmt(&**self, f) + } +} + +impl Display for PathBuf { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&**self, f) + } +} + #[cfg(test)] mod test { use super::PathBuf; -- cgit 1.4.1