Crate tokei [] [src]

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.


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 = &["**/*.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);



Struct representing a single Language.


A collection of existing languages(List of Languages)


A struct representing the statistics of a file.



Used for sorting languages.