Crates.io | dep-graph |
lib.rs | dep-graph |
version | 0.2.0 |
source | src |
created_at | 2020-07-05 16:55:30.165192 |
updated_at | 2020-12-27 19:17:06.493478 |
description | Dependency graph resolver library |
homepage | |
repository | https://github.com/nmoutschen/dep-graph |
max_upload_size | |
id | 261654 |
size | 35,541 |
This is a rust library to perform iterative operations over dependency graphs.
[dependencies]
dep-graph = "0.2"
This library supports both sequential and parallel (multi-threaded) operations out of the box. By default, multi-threaded operations will run a number of threads equal to the number of cores.
Here is a simple example on how to use this library:
use dep_graph::{Node, DepGraph};
#[cfg(feature = "parallel")]
use rayon::prelude::*;
// Create a list of nodes
let mut root = Node::new("root");
let mut dep1 = Node::new("dep1");
let mut dep2 = Node::new("dep2");
let leaf = Node::new("leaf");
// Map their connections
root.add_dep(dep1.id());
root.add_dep(dep2.id());
dep1.add_dep(leaf.id());
dep2.add_dep(leaf.id());
// Create a graph
let nodes = vec![root, dep1, dep2, leaf];
// Print the name of all nodes in the dependency graph.
// This will parse the dependency graph sequentially
{
let graph = DepGraph::new(&nodes);
graph
.into_iter()
.for_each(|node| {
println!("{:?}", node)
});
}
// This is the same as the previous command, excepts it leverages rayon
// to process them in parallel as much as possible.
#[cfg(feature = "parallel")]
{
let graph = DepGraph::new(&nodes);
graph
.into_par_iter()
.for_each(|node| {
// The node is a dep_graph::Wrapper object, not a String.
// We need to use `*node` to get its value.
println!("{:?}", *node)
});
}