Skip to main content

gather_stats

Function gather_stats 

Source
pub fn gather_stats(source: &str, context: VisitorContext) -> Locs
Expand description

Gather LOC statistics from a string of Rust source code.

The context determines how logic lines are categorized:

  • VisitorContext::Code โ†’ logic lines count as code
  • VisitorContext::Tests โ†’ logic lines count as tests
  • VisitorContext::Example โ†’ logic lines count as examples

Comments, docs, and blanks are always counted regardless of context.

ยงExample

use rustloclib::{gather_stats, VisitorContext};

let source = r#"
fn main() {
    println!("Hello");
}
"#;

let stats = gather_stats(source, VisitorContext::Code);
assert_eq!(stats.code, 3);