From 3120e62dda0f2a2285b8ca3166f16ff0ce1145bc Mon Sep 17 00:00:00 2001 From: dusk Date: Sat, 11 Jan 2025 19:51:45 +0900 Subject: [PATCH] refactor(commands): move tree branch construct code into type method --- crates/commands/src/lib.rs | 6 +----- crates/commands/src/tree.rs | 7 +++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/commands/src/lib.rs b/crates/commands/src/lib.rs index 2944e222..f7739cd2 100644 --- a/crates/commands/src/lib.rs +++ b/crates/commands/src/lib.rs @@ -10,7 +10,6 @@ uniffi::include_scaffolding!("commands"); use core::panic; use std::collections::HashMap; -use ordermap::OrderMap; use smol_str::{format_smolstr, SmolStr}; use tree::TreeBranch; @@ -19,10 +18,7 @@ pub use token::*; lazy_static::lazy_static! { pub static ref COMMAND_TREE: TreeBranch = { - let mut tree = TreeBranch { - current_command_key: None, - branches: OrderMap::new(), - }; + let mut tree = TreeBranch::empty(); crate::commands::all().into_iter().for_each(|x| tree.register_command(x)); diff --git a/crates/commands/src/tree.rs b/crates/commands/src/tree.rs index 77bd2f8c..27ee0791 100644 --- a/crates/commands/src/tree.rs +++ b/crates/commands/src/tree.rs @@ -10,6 +10,13 @@ pub struct TreeBranch { } impl TreeBranch { + pub fn empty() -> Self { + Self { + current_command_key: None, + branches: OrderMap::new(), + } + } + pub fn register_command(&mut self, command: Command) { let mut current_branch = self; // iterate over tokens in command