18 个版本
0.8.3 | 2021年11月26日 |
---|---|
0.8.2 | 2020年7月7日 |
0.8.1 | 2017年11月16日 |
0.7.1 | 2017年3月11日 |
0.5.2 | 2014年12月27日 |
150 在 科学
1,829 每月下载量
用于 4 个 Crates (3 个直接使用)
19KB
269 行
solvent
Solvent 是一个用 Rust 编写的依赖解析器库。
文档可在 https://docs.rs/solvent 查找
Solvent 通过构建依赖图并按顺序解析某些目标节点的依赖项,帮助您解决依赖顺序,使得每个输出仅依赖于之前的输出。
它目前相当简单,但仍然很有用。
节点类型应该很小(因为您将传递它们),并且应该实现 Eq。引用是不错的选择。
示例
extern crate solvent;
use solvent::DepGraph;
fn main() {
// Create a new empty DepGraph.
let mut depgraph: DepGraph<&str> = DepGraph::new();
// You can register a dependency like this. Solvent will automatically create nodes for any
// term it has not seen before. This means 'b' depends on 'd'
depgraph.register_dependency("b","d");
// You can also register multiple dependencies at once
depgraph.register_dependencies("a",vec!["b","c","d"]);
depgraph.register_dependencies("c",vec!["e"]);
// Iterate through each dependency of "a". The dependencies will be returned in an order such
// that each output only depends on the previous outputs (or nothing). The target itself will
// be output last.
for node in depgraph.dependencies_of(&"a").unwrap() {
print!("{} ", node.unwrap());
}
}
上面的代码将输出: d b e c a
或 e c d b a
或其他有效的依赖顺序。
该算法不是确定的,每次运行可能会给出不同的答案。
迭代器 dependencies_of() 返回一个 Option<Result<T, SolventError>>
。for 循环为您处理了 Option
部分,但您可能想要检查 SolventError
的结果。一旦返回错误,迭代器后续的所有调用 next()
将产生 None
。
您还可以标记某些元素为已满足,迭代器将考虑这一点
depgraph.mark_as_satisfied(["e","c"]).unwrap();
检测到依赖循环将返回 SolventError::CycleDetected
。
用例
以下示例情况中这类计算很有用
- 系统软件包管理:依赖于其他软件包的软件包
- 处理依赖项的构建系统,例如 'make' 或 'cargo'(注意:cargo 和 rustc 都不使用 solvent)
- 复杂的软件配置,如 Linux 内核配置
- 不需要严格顺序的数据库模式升级(例如,多个开发者可以在单独的 git 分支上独立提交数据库模式升级,而无需合并冲突)-- 作者编写 solvent 的目的就是为了这个。
此 crate 不是一个 SAT 求解器,它要简单得多。
其他详情
溶剂目前尚不支持布尔逻辑。请参阅问题编号 [#1](《https://github.com/mikedilger/solvent/issues/1》)。
依赖项
~185KB