Struct krates::Krates [−][src]
Expand description
A crate graph. Each unique crate is a node, and each unique dependency between 2 crates is an edge.
Implementations
Path to the Cargo.lock file for the crate or workspace where the graph metadata was acquired from
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
pub fn search_matches<'a: 'b, 'b>(
&'b self,
name: &'a str,
req: &'a VersionReq
) -> impl Iterator<Item = (NodeId, &Node<N>)>
pub fn search_matches<'a: 'b, 'b>(
&'b self,
name: &'a str,
req: &'a VersionReq
) -> impl Iterator<Item = (NodeId, &Node<N>)>
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
Auto Trait Implementations
impl<N, E> RefUnwindSafe for Krates<N, E> where
E: RefUnwindSafe,
N: RefUnwindSafe,
impl<N, E> UnwindSafe for Krates<N, E> where
E: UnwindSafe,
N: UnwindSafe,