Skip to main content

to_flat

Function to_flat 

Source
pub fn to_flat(roots: &[Cluster]) -> Vec<FlatCluster>
Expand description

Flatten a nested cluster tree into the §7.1 flat form.

The traversal is depth-first, parents emitted before children, so the output is suitable for streaming to --format=json-flat.

§Examples

use face_core::{Cluster, to_flat, from_flat};

let parent: Cluster = serde_json::from_value(serde_json::json!({
    "id": "file:src/cli.rs",
    "label": "src/cli.rs",
    "axis": "file",
    "value": "src/cli.rs",
    "total": 38,
    "score_min": null,
    "score_max": null,
    "clusters": []
})).unwrap();

let flat = to_flat(&[parent.clone()]);
assert_eq!(flat.len(), 1);
let nested = from_flat(&flat).unwrap();
assert_eq!(nested, vec![parent]);