Skip to main content

module_key

Function module_key 

Source
pub fn module_key(
    path: &str,
    module_roots: &[String],
    module_depth: usize,
) -> String
Expand description

Compute a “module key” from an input path.

Rules:

  • Root-level files become “(root)”.
  • If the first directory segment is in module_roots, join module_depth directory segments.
  • Otherwise, module key is the top-level directory.

§Examples

use tokmd_model::module_key;

let roots = vec!["crates".to_string()];
assert_eq!(module_key("crates/foo/src/lib.rs", &roots, 2), "crates/foo");
assert_eq!(module_key("src/lib.rs", &roots, 2), "src");
assert_eq!(module_key("Cargo.toml", &roots, 2), "(root)");