From f69890fa90267312d75f73cd6108d85c0a3369b8 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Mon, 3 Jun 2024 19:41:41 +0700 Subject: [PATCH 1/4] chore(release): 0.1.0 --- Cargo.toml | 24 +++++++++++++++++++++--- src/lib.rs | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5dbcaa5..161fd4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,26 @@ [package] name = "easy-tree" version = "0.1.0" +authors = ["Anton Suprunchuk "] edition = "2021" +description = "A simple and efficient tree structure library for Rust with recursive traversal" +homepage = "https://github.com/antouhou/easy-tree" +repository = "https://github.com/antouhou/easy-tree" +license = "MIT" +keywords = ["tree", "traversal", "data_structure", "hierarchical", "recursive"] +categories = ["data-structures", "algorithms"] +readme = "README.md" -[dependencies.rayon] -version = "1.10.0" -optional = true \ No newline at end of file +[dependencies] +# Add other dependencies here +rayon = { version = "1.10", optional = true } + +[features] +default = [] + +[badges] +github-actions = { repository = "antouhou/easy-tree" } + +# For documentation purpose +[package.metadata.docs.rs] +features = ["rayon"] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index cb5b3b3..7cbea74 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -317,26 +317,36 @@ mod tests { let mut tree = Tree::new(); let root = tree.add_node(0); // Root node with data 0 let child1 = tree.add_child(root, 1); // Child node with data 1 - let child2 = tree.add_child(root, 2); // Child node with data 2 - let child3 = tree.add_child(child1, 3); // Child node with data 3 + let _child2 = tree.add_child(root, 2); // Child node with data 2 + let _child3 = tree.add_child(child1, 3); // Child node with data 3 let mut result = vec![]; - tree.traverse(|index, node, result| { - result.push(format!("Calling handler for node {}: {}", index, node)) - }, |index, node, result| { - result.push(format!("Finished handling node {} and all it's children", index)) - }, &mut result); - - assert_eq!(result, vec![ - "Calling handler for node 0: 0", - "Calling handler for node 1: 1", - "Calling handler for node 3: 3", - "Finished handling node 3 and all it's children", - "Finished handling node 1 and all it's children", - "Calling handler for node 2: 2", - "Finished handling node 2 and all it's children", - "Finished handling node 0 and all it's children", - ]); + tree.traverse( + |index, node, result| { + result.push(format!("Calling handler for node {}: {}", index, node)) + }, + |index, _node, result| { + result.push(format!( + "Finished handling node {} and all it's children", + index + )) + }, + &mut result, + ); + + assert_eq!( + result, + vec![ + "Calling handler for node 0: 0", + "Calling handler for node 1: 1", + "Calling handler for node 3: 3", + "Finished handling node 3 and all it's children", + "Finished handling node 1 and all it's children", + "Calling handler for node 2: 2", + "Finished handling node 2 and all it's children", + "Finished handling node 0 and all it's children", + ] + ); } } From 7ed041568a3f97ce6f38e6c71db8eebb453365d5 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Mon, 3 Jun 2024 19:42:32 +0700 Subject: [PATCH 2/4] reformat Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 161fd4e..a2c3f59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,4 @@ github-actions = { repository = "antouhou/easy-tree" } # For documentation purpose [package.metadata.docs.rs] -features = ["rayon"] \ No newline at end of file +features = ["rayon"] From aa872e5f9f3553ddfd36959e75d1d000b75812fb Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Mon, 3 Jun 2024 19:44:48 +0700 Subject: [PATCH 3/4] fix actions --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3b8d022..90d17cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,9 @@ name: Build and test on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: test: From 5d3b89e3a90f4ca481776745493dc3d38643afc0 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Mon, 3 Jun 2024 19:49:03 +0700 Subject: [PATCH 4/4] fix clippy warnings --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7cbea74..062a1f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -128,9 +128,7 @@ impl Tree { /// Adds a child node with the given data to the root node and returns the child's index. pub fn add_child_to_root(&mut self, data: T) -> usize { - let index = self.add_child(0, data); - - index + self.add_child(0, data) } /// Returns a reference to the data of the node at the given index, or `None` if the index is