From a2c33f517c217a196bce92f6acd4f6552cb85275 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 all nodes 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 --- tvix/store/src/proto.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tvix/store/src') 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. -- cgit 1.4.1