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 <tazjin@tvl.su>
This commit is contained in:
Florian Klink 2023-01-29 17:42:54 +01:00 committed by flokli
parent 9c18888715
commit a2c33f517c

View file

@ -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. /// 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 the passed name is larger than the previous one, the reference is updated.
/// If it's not, an error is returned. /// If it's not, an error is returned.