[][src]Struct krates::Krates

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

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

Methods

impl<N, E> Krates<N, E>[src]

pub fn len(&self) -> usize[src]

The number of unique crates in the graph

pub fn lock_path(&self) -> &PathBuf[src]

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

pub fn graph(&self) -> &Graph<Node<N>, E>[src]

Get access to the raw petgraph

pub fn krates(&self) -> impl Iterator<Item = &Node<N>>[src]

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);
    }
}

pub fn get_deps(&self, id: NodeId) -> impl Iterator<Item = (&Node<N>, &E)>[src]

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()
}

pub fn nid_for_kid(&self, kid: &Kid) -> Option<NodeId>[src]

Get the node identifier for the specified crate identifier

pub fn node_for_kid(&self, kid: &Kid) -> Option<&Node<N>>[src]

Get the node for the specified crate identifier

pub fn workspace_members(&self) -> impl Iterator<Item = &Node<N>>[src]

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

impl<N, E> Krates<N, E> where
    N: KrateDetails
[src]

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>)>
[src]

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);
    }
}

pub fn krates_by_name(
    &self,
    name: &str
) -> impl Iterator<Item = (NodeId, &Node<N>)>
[src]

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

impl<N, E> Index<NodeIndex<u32>> for Krates<N, E>[src]

type Output = N

The returned type after indexing.

impl<N, E> Index<usize> for Krates<N, E>[src]

type Output = N

The returned type after indexing.

Auto Trait Implementations

impl<N, E> RefUnwindSafe for Krates<N, E> where
    E: RefUnwindSafe,
    N: RefUnwindSafe

impl<N, E> Send for Krates<N, E> where
    E: Send,
    N: Send

impl<N, E> Sync for Krates<N, E> where
    E: Sync,
    N: Sync

impl<N, E> Unpin for Krates<N, E> where
    E: Unpin,
    N: Unpin

impl<N, E> UnwindSafe for Krates<N, E> where
    E: UnwindSafe,
    N: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.