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§
pub use cm::Metadata;pub use cm::Package;pub use cm::PackageId;pub use cfg_expr;pub use petgraph;pub use semver;pub use self;
Modules§
- cm
- Internal version of
cargo_metadata - index
- Utilities for fixing features in metadata with information from an index
Structs§
- Builder
- A builder used to create a Krates graph, either by running a cargo metadata
command, or using an already deserialized [
cargo_metadata::Metadata] - Cmd
- An alternative to [
cargo_metadata::MetadataCommand]. - Direct
Dependency - A direct dependency of a crate
- Direct
Dependent - A crate that has a direct dependency on another crate
- Kid
- A crate’s unique identifier
- Krate
Match - A match for a crate query
- Krates
- A crate graph. Each unique crate is a node, and each unique dependency between 2 crates is an edge.
- Lock
Options - Options related to how the lockfile and network is utilized.
- None
Filter - For when you just want to satisfy
OnFilterwithout doing anything - Parsed
Feature - A parsed feature
- PkgSpec
- A package specification.
- Utf8
Path - A slice of a UTF-8 path (akin to
str). - Utf8
Path Buf - An owned, mutable UTF-8 path (akin to
String).
Enums§
- DepKind
- The dependency kind.
- Edge
- The default type used for edges in the crate graph.
- Error
- Errors that can occur when acquiring metadata to create a graph from
- Feature
- A feature declared by a crate
- Node
- A node in the crate graph.
- Scope
- The scope for which a dependency kind will be ignored
- Target
- A target to filter crates by
Traits§
- Krate
Details - A trait that can be applied to the type stored in the graph nodes to give
additional features on
Krates. - OnFilter
- Trait used to report back any crates that are completely ignored in the final crate graph that is built.
Type Aliases§
- EdgeId
- An edge identifier.
- Enabled
Features - The set of features that have been enabled on a crate
- NodeId
- A node identifier.