about summary refs log tree commit diff
path: root/tvix/castore
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2024-05-01T11·20+0000
committeredef <edef@edef.eu>2024-05-01T11·27+0000
commitc5b318700235113fc687dcf9b201d64e775fc9d6 (patch)
tree139f8dbf3d407b4f8175c188c54548374689c22b /tvix/castore
parentccb93a65a832caa163ae0ddbc80a7ca0d8868d5a (diff)
feat(tvix/castore/path): implement Debug + Display r/8052
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 <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore')
-rw-r--r--tvix/castore/src/path.rs36
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;