about summary refs log tree commit diff
path: root/tvix/store/src/proto.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-01-29T16·42+0100
committerflokli <flokli@flokli.de>2023-01-30T09·45+0000
commita2c33f517c217a196bce92f6acd4f6552cb85275 (patch)
tree93ab48a0786e80db26c7117798e7977bfe7fe55e /tvix/store/src/proto.rs
parent9c18888715ffb41806017190ac66037709215b4b (diff)
feat(tvix/store/proto): implement get_name for all nodes r/5779
Also add a `NamedNode` trait. We'll later use this to access names from
all three individually.

Change-Id: Icb5afd6fa5a0d834e9908294382de9892a5a6440
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7953
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/store/src/proto.rs')
-rw-r--r--tvix/store/src/proto.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tvix/store/src/proto.rs b/tvix/store/src/proto.rs
index 0b4e11bebf89..0c4a894c23b5 100644
--- a/tvix/store/src/proto.rs
+++ b/tvix/store/src/proto.rs
@@ -150,6 +150,30 @@ impl PathInfo {
     }
 }
 
+/// NamedNode is implemented for [FileNode], [DirectoryNode] and [SymlinkNode],
+/// so we can ask all three for their name easily.
+trait NamedNode {
+    fn get_name(&self) -> &str;
+}
+
+impl NamedNode for &FileNode {
+    fn get_name(&self) -> &str {
+        self.name.as_str()
+    }
+}
+
+impl NamedNode for &DirectoryNode {
+    fn get_name(&self) -> &str {
+        self.name.as_str()
+    }
+}
+
+impl NamedNode for &SymlinkNode {
+    fn get_name(&self) -> &str {
+        self.name.as_str()
+    }
+}
+
 /// Accepts a name, and a mutable reference to the previous name.
 /// If the passed name is larger than the previous one, the reference is updated.
 /// If it's not, an error is returned.