[][src]Crate tokei

Tokei: Count your code quickly.

A simple, efficient library for counting code in directories. This functionality is also provided as a CLI utility. Tokei uses a small state machine rather than regular expressions found in other code counters. Tokei can accurately count a lot more edge cases such as nested comments, or comment syntax inside string literals.

Examples

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

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

use tokei::{Config, Languages, LanguageType};

// The paths to search. Accepts absolute, relative, and glob paths.
let paths = &["src", "tests"];
// Exclude any path that contains any of these strings.
let excluded = &["target"];
// `Config` allows you to configure what is searched and counted.
let config = Config::default();

let mut languages = Languages::new();
languages.get_statistics(paths, excluded, &config);
let rust = &languages[&LanguageType::Rust];

println!("Lines of code: {}", rust.code);

Structs

CodeStats

A struct representing stats about a single blob of code.

Config

A configuration struct for how Languages::get_statistics searches and counts languages.

Language

A struct representing statistics about a single Language.

Languages

A newtype representing a list of languages counted in the provided directory. (List of Languages)

Report

A struct representing the statistics of a file.

Enums

LanguageType

Represents a individual programming language. Can be used to provide information about the language, such as multi line comments, single line comments, string literal syntax, whether a given language allows nesting comments.

Sort

Used for sorting languages.