3个版本
0.1.2 | 2023年7月13日 |
---|---|
0.1.1 | 2023年7月13日 |
0.1.0 | 2023年7月13日 |
#1978 in 算法
7KB
91 行
dep_crusher
从根节点开始,遍历其整个依赖图并将其扁平化为从上到下的列表。节点是一个特质实现,这使得dep_crusher具有通用和广泛的应用。
安装
有两种简单的安装选项。
- 使用终端中的Cargo
cargo add dep_crusher
- 将依赖项添加到您的
Cargo.toml
文件
[dependencies]
dep_crusher = "0.1.0"
使用
- 实现
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>
}
}
- 粉碎依赖关系!
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。请随意改进它!对于重大更新,请首先提交一个问题来讨论您想要更改的内容。
请确保适当地更新测试。