about summary refs log tree commit diff
path: root/tvix/store/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-01-29T16·42+0100
committerflokli <flokli@flokli.de>2023-01-31T13·29+0000
commit1ee6bd06e32d49690f536a2a5a901055d69bc1c0 (patch)
treed40c853e2109252de63389af030c983386f78ba3 /tvix/store/src
parentc27bacd905a14207edc56850fd4ef9383706b5c4 (diff)
feat(tvix/store/proto): implement get_name for node::Node, pub trait r/5789
Make the trait public, so consumers can use it.

Also, implement it for node::Node, so we can later use this to access
the name from all three if we don't care about the enum type.

Change-Id: Iae530a16b705493645e61947852c03273876cc55
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7963
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src')
-rw-r--r--tvix/store/src/proto.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/tvix/store/src/proto.rs b/tvix/store/src/proto.rs
index fc5db4446d5e..82a2d09ee5b7 100644
--- a/tvix/store/src/proto.rs
+++ b/tvix/store/src/proto.rs
@@ -150,9 +150,9 @@ impl PathInfo {
     }
 }
 
-/// NamedNode is implemented for [FileNode], [DirectoryNode] and [SymlinkNode],
-/// so we can ask all three for their name easily.
-trait NamedNode {
+/// NamedNode is implemented for [FileNode], [DirectoryNode] and [SymlinkNode]
+/// and [node::Node], so we can ask all of them for the name easily.
+pub trait NamedNode {
     fn get_name(&self) -> &str;
 }
 
@@ -174,6 +174,16 @@ impl NamedNode for &SymlinkNode {
     }
 }
 
+impl NamedNode for node::Node {
+    fn get_name(&self) -> &str {
+        match self {
+            node::Node::File(node_file) => &node_file.name,
+            node::Node::Directory(node_directory) => &node_directory.name,
+            node::Node::Symlink(node_symlink) => &node_symlink.name,
+        }
+    }
+}
+
 /// 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.