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.

Example

extern crate solvent;

use solvent::DepGraph;

fn main() {
    // Create a new empty DepGraph.  Must be `mut` or else it cannot
    // be used by the rest of the library.
    let mut depgraph: DepGraph = 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",&["b","c","d"]);
    depgraph.register_dependencies("c",&["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") {
        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>. 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 elements as already satisfied, and the iterator will take that into account:

depgraph.mark_as_satisfied(["e","c"]);

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

Structs

DepGraph

This is the dependency graph.

DepGraphIterator

This iterates through the dependencies of the DepGraph's target

Enums

SolventError