#graph #root-node #graph-traversal #tree #dependencies

dep_crusher

从根节点开始,遍历依赖图并将其扁平化

3个版本

0.1.2 2023年7月13日
0.1.1 2023年7月13日
0.1.0 2023年7月13日

#1978 in 算法

MIT/Apache

7KB
91

dep_crusher

从根节点开始,遍历其整个依赖图并将其扁平化为从上到下的列表。节点是一个特质实现,这使得dep_crusher具有通用和广泛的应用。

安装

有两种简单的安装选项。

  1. 使用终端中的Cargo
cargo add dep_crusher
  1. 将依赖项添加到您的Cargo.toml文件
[dependencies]
dep_crusher = "0.1.0"

使用

  1. 实现dep_crusher::dep_node::Node特质
struct MyStruct {
    // ...
}

impl PartialEq for MyStruct {
    fn eq(&self, other: &Self) -> bool {
        // Check equality with, for example, and ID
    }
}

impl dep_crusher::dep_node::Node for MyStruct {
    type Id = u64; // Type that implements Eq + Hash;

    fn get_id(&self) -> Self::Id {
        // Get a unique identifier of MyStruct
    }

    fn get_next(&self) -> Vec<Self> {
        // Get and return the next Vec<MyStruct>
    }
}
  1. 粉碎依赖关系!
let my_struct = MyStruct {
  // ...
}

let ordered_dependencies = my_struct.crush();
// OR
let ordered_dependencies = dep_crusher::crush(my_struct);

// Returns dep_crusher::result::Result<MyStruct>
// The Ok variant is Vec<MyStruct>
// The Error variant is dep_crusher::result::Error<MyStruct>

贡献

欢迎Pull requests。请随意改进它!对于重大更新,请首先提交一个问题来讨论您想要更改的内容。

请确保适当地更新测试。

许可证

MITApache-2.0

无运行时依赖