tokei 4.5.1

A utility that allows you to count code, quickly.
Documentation

Tokei: Code Analysis Library

A simple, effcient library for counting code in directories. For the binary

How to use

Tokei provides both Languages struct which a map of many existing programming languages, and Language for creating custom languages.

Example

Gets the total lines of code from all rust files in current directory, and all subdirectories.

extern crate tokei;

use std::collections::BTreeMap;
use std::fs::File;
use std::io::Read;

use tokei::{Languages, LanguageType};

fn main() {
    // The paths to search. Accepts absolute, relative, and glob paths.
    let paths = vec!["**/*.rs"];
    // Exclude any path that contains any of these strings.
    let excluded = vec!["target", ".git"];

    // Create new Languages
    let mut languages = Languages::new();

    // Get statistics
    languages.get_statistics(paths, excluded);

    // Remove empty languages
    let language_map = languages.remove_empty();

    // Get Rust from statistics
    let rust = language_map.get(&LanguageType::Rust).unwrap();

    // Print the number of lines that were code.
    println!("Lines of code: {}", rust.code);
}