Crate krates

source ·
Expand description

Transforms the output of [cargo metadata] into a graph, Krates, where crates are nodes and dependency links are edges.

use krates::{Builder, Cmd, Krates, cm, petgraph};

fn main() -> Result<(), krates::Error> {
    let mut cmd = Cmd::new();
    cmd.manifest_path("path/to/a/Cargo.toml");
    // Enable all features, works for either an entire workspace or a single crate
    cmd.all_features();

    let mut builder = Builder::new();
    // Let's filter out any crates that aren't used by x86_64 windows
    builder.include_targets(std::iter::once(("x86_64-pc-windows-msvc", vec![])));

    let krates: Krates = builder.build(cmd, |pkg: cm::Package| {
        println!("Crate {} was filtered out", pkg.id);
    })?;

    // Print a dot graph of the entire crate graph
    println!("{:?}", petgraph::dot::Dot::new(krates.graph()));

    Ok(())
}

Re-exports§

Modules§

Structs§

Enums§

  • The dependency kind. A crate can depend on the same crate multiple times with different dependency kinds
  • The default type used for edges in the crate graph.
  • Errors that can occur when acquiring metadata to create a graph from
  • A node in the crate graph.
  • The scope for which a dependency kind will be ignored

Traits§

  • A trait that can be applied to the type stored in the graph nodes to give additional features on Krates.
  • Trait used to report back any crates that are completely ignored in the final crate graph that is built. This occurs when the crate has no dependents any longer due to the applied filters.

Type Aliases§