diff options
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/castore/src/path.rs | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/tvix/castore/src/path.rs b/tvix/castore/src/path.rs index 8cca5b62f822..3577ea80a4a9 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<u8>, } @@ -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; |