tokei_tokens/lib.rs
1//! # Tokei: Count your code quickly.
2//!
3//! A simple, efficient library for counting code in directories. This
4//! functionality is also provided as a
5//! [CLI utility](//github.com/XAMPPRocky/tokei). Tokei uses a small state
6//! machine rather than regular expressions found in other code counters. Tokei
7//! can accurately count a lot more edge cases such as nested comments, or
8//! comment syntax inside string literals.
9//!
10//! # Examples
11//!
12//! Gets the total lines of code from all rust files in current directory,
13//! and all subdirectories.
14//!
15//! ```no_run
16//! use std::collections::BTreeMap;
17//! use std::fs::File;
18//! use std::io::Read;
19//!
20//! use tokei_tokens::{Config, Languages, LanguageType};
21//!
22//! // The paths to search. Accepts absolute, relative, and glob paths.
23//! let paths = &["src", "tests"];
24//! // Exclude any path that contains any of these strings.
25//! let excluded = &["target"];
26//! // `Config` allows you to configure what is searched and counted.
27//! let config = Config::default();
28//!
29//! let mut languages = Languages::new();
30//! languages.get_statistics(paths, excluded, &config);
31//! let rust = &languages[&LanguageType::Rust];
32//!
33//! println!("Lines of code: {}", rust.code);
34//! ```
35
36#![deny(
37 trivial_casts,
38 trivial_numeric_casts,
39 unused_variables,
40 unstable_features,
41 unused_import_braces,
42 missing_docs
43)]
44
45#[macro_use]
46extern crate log;
47#[macro_use]
48extern crate serde;
49
50#[macro_use]
51mod utils;
52mod config;
53mod consts;
54mod language;
55mod sort;
56mod stats;
57
58pub use self::{
59 config::Config,
60 consts::*,
61 language::{Language, LanguageType, Languages},
62 sort::Sort,
63 stats::{find_char_boundary, CodeStats, Report},
64};