Struct krates::Krates[][src]

pub struct Krates<N = Package, E = Edge> { /* fields omitted */ }
Expand description

A crate graph. Each unique crate is a node, and each unique dependency between 2 crates is an edge.

Implementations

The number of unique crates in the graph

Path to the Cargo.lock file for the crate or workspace where the graph metadata was acquired from

Get access to the raw petgraph

Get an iterator over the crate nodes in the graph. The crates are always ordered lexicographically by their identfier.

use krates::Krates;

fn print_krates(krates: &Krates) {
    for (name, version) in krates.krates().map(|kn| (&kn.krate.name, &kn.krate.version)) {
        println!("Crate {} @ {}", name, version);
    }
}

Get an iterator over each dependency of the specified crate. The same dependency can be returned multiple times if the crate depends on it with more than 1 dependency kind.

use krates::{Krates, Kid, DepKind};

fn count_build_deps(krates: &Krates, pkg: &Kid) -> usize {
    krates.get_deps(krates.nid_for_kid(pkg).unwrap())
        .filter(|(_, edge)| edge.kind == DepKind::Build)
        .count()
}

Get the node identifier for the specified crate identifier

Get the node for the specified crate identifier

Get an iterator over the nodes for the members of the workspace

If the node type N supports KrateDetails, we can also iterator over krates of a given name and or version

Get an iterator over the crates that match the specified name, as well as satisfy the specified semver requirement.

use krates::{Krates, semver::VersionReq};

fn print(krates: &Krates, name: &str) {
    let req = VersionReq::parse("=0.2").unwrap();
    for vs in krates.search_matches(name, &req).map(|(_, kn)| &kn.krate.version) {
        println!("found version {} matching {}!", vs, req);
    }
}

Get an iterator over all of the crates in the graph with the given name, in the case there are multiple versions, or sources, of the crate.

use krates::Krates;

fn print_all_versions(krates: &Krates, name: &str) {
    for vs in krates.krates_by_name(name).map(|(_, kn)| &kn.krate.version) {
        println!("found version {}", vs);
    }
}

Trait Implementations

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.