nornir 0.4.0

Companion to cargo: dependency tracking, release gating, deploy, benchmarks, and documentation assembly. Project-agnostic.
Documentation
//! Workspace + external deps from `cargo metadata`, via the canonical
//! `cargo_metadata` crate (pure-Rust API; no manual subprocess).

use std::path::Path;

use anyhow::{Context, Result};
use cargo_metadata::MetadataCommand;

use super::{Edge, EdgeKind, Graph};

pub fn extract(repo_root: &Path) -> Result<Graph> {
    let meta = MetadataCommand::new()
        .current_dir(repo_root)
        .no_deps()
        .exec()
        .context("cargo_metadata::MetadataCommand::exec")?;
    let mut g = Graph::default();
    for p in &meta.packages {
        g.nodes.push(p.name.to_string());
        for d in &p.dependencies {
            g.edges.push(Edge {
                from: p.name.to_string(),
                to: d.name.clone(),
                kind: EdgeKind::DependsOn,
            });
        }
    }
    Ok(g)
}