This commit is contained in:
Olivier 'reivilibre' 2022-11-19 15:28:36 +00:00
parent 58c5c3f039
commit cf502b7f7e
2 changed files with 8 additions and 20 deletions

View File

@ -274,25 +274,13 @@ impl TreeNode {
/// Recurses into a child by name, or returns Err with a reason.
pub fn child(&mut self, name: &str) -> Result<&mut TreeNode, &'static str> {
match self {
TreeNode::NormalFile { .. } => {
Err("not a directory: normal file")
}
TreeNode::Directory { children, .. } => {
match children.get_mut(name) {
None => {
Err("child not in directory")
}
Some(node) => {
Ok(node)
}
}
}
TreeNode::SymbolicLink { .. } => {
Err("not a directory: symlink")
}
TreeNode::Deleted => {
Err("not a directory: deleted")
}
TreeNode::NormalFile { .. } => Err("not a directory: normal file"),
TreeNode::Directory { children, .. } => match children.get_mut(name) {
None => Err("child not in directory"),
Some(node) => Ok(node),
},
TreeNode::SymbolicLink { .. } => Err("not a directory: symlink"),
TreeNode::Deleted => Err("not a directory: deleted"),
}
}
}