cargo-treemap 0.1.0

Interactive treemap analyzer for Rust binary size and dependency API usage — like webpack-bundle-analyzer, for cargo.
//! Machine-readable JSON: `{ meta, tree }`. Stable enough to diff two runs in CI.

use crate::apiusage::DepValue;
use crate::model::{Meta, Node};
use crate::parity::CrateRow;
use anyhow::Result;
use serde::Serialize;

#[derive(Serialize)]
struct Report<'a> {
    meta: &'a Meta,
    dependencies: &'a [DepValue],
    crates: &'a [CrateRow],
    tree: &'a Node,
}

pub fn render(root: &Node, meta: &Meta, deps: &[DepValue], crates: &[CrateRow]) -> Result<String> {
    let report = Report {
        meta,
        dependencies: deps,
        crates,
        tree: root,
    };
    Ok(serde_json::to_string_pretty(&report)?)
}