Crate solvent [] [src]

Solvent is a dependency resolver library written in rust.

Solvent helps you to resolve dependency orderings by building up a dependency graph and then resolving the dependences of some target node in an order such that each output depends only upon the previous outputs.

It is currently quite simple, but is still useful.


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'

    // You can also register multiple dependencies at once

    // 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() {
        match node {
            Ok(n) => print!("{} ", n),
            Err(e) => panic!("Solvent error detected: {:?}", e),

The above will output: d b e c a or e c d b a or some other valid dependency order.

The algorithm is not deterministic, and may give a different answer each time it is run. Beware.

The iterator dependencies_of() returns an Option<Result<T ,SolventError>>. The for loop handles the Option part for you, but you may want to check the result for SolventErrors. Once an error is returned, all subsequent calls to the iterator next() will yield None.

You can also mark some nodes as already satisfied, and the iterator will take that into account

Be careful when using this code, it's not being tested!

Dependency cycles are detected and will return SolventError::CycleDetected.





This is the dependency graph. The type T is intended to be a small type, or a reference to a larger type that implements Eq (you will need to supply the type and vectors of the type to functions).


This iterates through the dependencies of the DepGraph's target