From e50e1ef310d849bb2040dd9ab57654a31a1a5d7b Mon Sep 17 00:00:00 2001 From: ynqa Date: Sun, 11 Feb 2024 11:19:46 +0900 Subject: [PATCH] tree: add is_leaf field --- src/core/tree/node.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/tree/node.rs b/src/core/tree/node.rs index ebde87b2..4eed5cac 100644 --- a/src/core/tree/node.rs +++ b/src/core/tree/node.rs @@ -10,6 +10,7 @@ pub struct NodeWithDepth { pub data: String, pub depth: usize, pub children_visible: bool, + pub is_leaf: bool, } impl Node { @@ -38,6 +39,7 @@ impl Node { data: self.data.clone(), depth, children_visible: self.children_visible, + is_leaf: self.children.is_empty(), }); if self.children_visible && !self.children.is_empty() { @@ -89,6 +91,7 @@ mod test { data: String::from("/"), depth: 0, children_visible: false, + is_leaf: false, }], create_test_node().flatten() ); @@ -121,21 +124,25 @@ mod test { data: String::from("/"), depth: 0, children_visible: true, + is_leaf: false, }, NodeWithDepth { data: String::from("a"), depth: 1, children_visible: false, + is_leaf: false, }, NodeWithDepth { data: String::from("b"), depth: 1, children_visible: false, + is_leaf: true, }, NodeWithDepth { data: String::from("c"), depth: 1, children_visible: false, + is_leaf: true, }, ]; assert_eq!(expect, root.flatten());