mitoo 0.3.0

mitoo is a Rust toolkit library that encapsulates methods such as configuration reading, file operations, encryption and decryption, transcoding, regular expressions, threading, collections, trees, sqlite, rabbitMQ, etc., and customizes or integrates various Util tool classes.
Documentation
use mitoo::{TreeData, TreeUtil};

// ------------------------------
// 使用示例
// ------------------------------
#[derive(Debug, Clone)]
struct Menu {
    id: u64,
    name: String,
    pid: u64,
    // 可添加其他自定义字段
}

// 为 Menu 实现 TreeData 约束
impl TreeData for Menu {
    type Id = u64;
    fn id(&self) -> Self::Id { self.id }
    fn name(&self) -> &str { &self.name }
    fn pid(&self) -> Self::Id { self.pid }
    // 定义根节点的父 ID 为 0
    fn root_pid() -> Self::Id { 0 }
}

mod tests {
    use super::*;
    #[test]
    fn test01() {
        // 准备扁平数据
        let menus = vec![
            Menu {
                id: 1,
                name: "系统管理".to_string(),
                pid: 0,
            },
            Menu {
                id: 2,
                name: "用户管理".to_string(),
                pid: 1,
            },
            Menu {
                id: 3,
                name: "角色管理".to_string(),
                pid: 1,
            },
            Menu {
                id: 4,
                name: "菜单管理".to_string(),
                pid: 2,
            },
            Menu {
                id: 5,
                name: "数据统计".to_string(),
                pid: 0,
            },
        ];

        // 转换为树形结构
        let trees = TreeUtil::to_trees(menus);
        println!("{:#?}", trees);
    }
}