Skip to main content

roll_up

Function roll_up 

Source
pub fn roll_up(files: &[FileStat]) -> (Counts, Vec<ModuleNode>)
Expand description

Roll a crate’s FileStats into whole-crate Counts (every file) plus a per-module breakdown (only files under the source root, bucketed by module_name), the modules sorted by name. The whole-crate total can exceed the module sum: files outside the source root (integration tests, benches) count toward the crate but belong to no module.

§Examples

use coding_tools::survey::{roll_up, FileStat};

let files = vec![
    FileStat { rel_to_src: Some("lib.rs".into()), lines: 10, words: 20, chars: 100, tests: 1 },
    FileStat { rel_to_src: Some("a/mod.rs".into()), lines: 5, words: 8, chars: 40, tests: 0 },
    FileStat { rel_to_src: None, lines: 3, words: 4, chars: 20, tests: 2 }, // a tests/ file
];
let (crate_counts, modules) = roll_up(&files);
assert_eq!(crate_counts.files, 3);
assert_eq!(crate_counts.lines, 18);
assert_eq!(crate_counts.tests, 3);
// Two modules: `a` and `crate` (lib.rs); the tests/ file is in neither.
assert_eq!(modules.len(), 2);
assert_eq!(modules[0].name, "a");
assert_eq!(modules[1].name, "crate");