Skip to main content

blast_radius

Function blast_radius 

Source
pub fn blast_radius(
    metadata: &str,
    changed: &[&str],
) -> Result<BlastRadius, String>
Expand description

Computes the blast radius of changed against metadata, the output of cargo metadata --no-deps --format-version 1.

Paths in changed may be absolute or relative to the workspace root; both are matched against each package’s directory. A file is attributed to the longest matching package directory, so a nested package wins over the workspace root.

§Errors

Returns a description when metadata is not JSON, or lacks the packages array with name and manifest_path on each entry.

§Examples

let metadata = r#"{"packages":[
  {"name":"lib","manifest_path":"/w/lib/Cargo.toml","dependencies":[]},
  {"name":"app","manifest_path":"/w/app/Cargo.toml",
   "dependencies":[{"name":"lib"}]}
]}"#;
// Touching the leaf reaches only itself.
let r = blast_radius(metadata, &["/w/app/src/main.rs"]).unwrap();
assert_eq!(r.reached, ["app"]);
// Touching the library reaches its dependent too.
let r = blast_radius(metadata, &["/w/lib/src/lib.rs"]).unwrap();
assert_eq!(r.reached, ["app", "lib"]);