From 1ee6bd06e32d49690f536a2a5a901055d69bc1c0 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 29 Jan 2023 17:42:54 +0100 Subject: feat(tvix/store/proto): implement get_name for node::Node, pub trait 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 Tested-by: BuildkiteCI --- tvix/store/src/proto.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tvix/store/src') 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. -- cgit 1.4.1