Skip to main content

Crate mezura_core

Crate mezura_core 

Source
Expand description

Counts the lines of a codebase: which language every file is written in, and how many of its lines are code, comments and neither.

A run takes two things. EngineConfig says what to count, and Languages says what the symbols of each language are. The second is built against the first and refuses to be used with any other, since counting Rust with settings that name Python would give figures that look perfectly normal and describe something else.

use mezura_core::{CountingModel, EngineConfig, Languages, run};

let config = EngineConfig::new(["./src", "./tests"]);
let (languages, warnings) = Languages::shipped(&config);
for warning in &warnings {
    eprintln!("{}", warning.message);
}

let result = run(&config, languages)?;
for (name, stats) in result.sort_languages_by(Default::default(), CountingModel::Content) {
    println!("{name}: {} code", stats.calculate_code_lines(CountingModel::Content));
}

Every line is sorted into one of the nine LineClasses, and a CountingModel folds those nine into the three columns of a report, so one run answers both models.

run_watched is the same run for a caller that needs real time feedback while it happens, and explain_file reads a single file line by line and says why each line was counted the way it was.

Re-exports§

pub use engine::config::EngineConfig;
pub use engine::config::ForcedLanguages;
pub use engine::config::LanguageNames;
pub use engine::config::ScopedByModule;
pub use engine::config::Target;
pub use engine::config::Threads;
pub use engine::config::format_module_scope;
pub use engine::config::split_off_module_scope;
pub use engine::targets::TargetError;
pub use languages::LanguageClaims;
pub use languages::Languages;
pub use warnings::Affects;
pub use warnings::Code;
pub use warnings::Warning;

Modules§

engine
The machinery that turns a set of targets into a result.
language_file
The format of a language file, which is the one thing under this roof that decides a number: what a language is called, which extensions it claims and which symbols open a comment.
languages
Which languages a run has in play, and which of them owns an extension two of them claim. The format a language file is written in is crate::language_file next door.
render
The arithmetic behind showing a result: shares, percentages, and how a number reads to a person. Nothing here decides a color, a width or a word, and nothing reads a global.
warnings
What a run wants the caller to know without it being an error: an answer was produced, and this says what to be careful about in it.

Structs§

Claim
One name a language claims, and which language a file wearing it is counted as.
ExplainedLine
What one line of the file came to.
FaultyFileDetails
A file that could not be read or parsed. Its lines are in no total, but it is counted among the files that were seen.
FileEntry
One counted file.
FileExplanation
One file read line by line, as explain_file answers it.
FilesPresent
How much of what the scan saw it had reason to count.
Keyword
A word worth counting occurrences of, under a name of its own.
Language
One language: what it is called, which files belong to it, and the symbols that decide what each of their lines is.
LeveledPair
A long-bracket comment pair, split around the run of = that gives it its level: --[=*[ is the prefix --[ and the suffix [.
LineClasses
Where each line of a file landed, one slot per line, so the nine always add up to the lines.
LineContinuation
A line ending in this symbol is joined to the one after it, before anything is decided about either.
ModuleResult
One module and its own figures. A module is a target that was given a name, as in mezura frontend=./web backend=./api.
MultilineString
A string that crosses lines: the same symbol twice for Python’s """, two different ones for a raw form like r#" with "#.
NestedLanguage
One section of another language inside a file: everything between the two tags is counted with that language’s own symbols.
Performance
What the run cost.
RunResult
Everything one run of crate::run produced.
ScanProgress
How far a run has got, for a caller that needs real time feedback.
SkippedFiles
The paths of the files a run set aside after reading their head, by the reason each was set aside for.
Span
One stretch of a line, as crate::explain_file reports it: which bytes sit inside a string, which inside a comment, and which outside both.
Stats
What was counted, for one language, one module or a whole run.
StringRules
The symbols that open a string, and the one byte that cancels the symbol standing after it: the backslash in most languages, the backtick in PowerShell, and nothing in the family that escapes a quote by doubling it, which is what Pascal, Ada, Fortran, COBOL and standard SQL need.
UnreadableDirDetails
A directory that could not be opened, so nothing inside it reached any figure.

Enums§

Bucket
One of the three columns a report shows, which is what a CountingModel folds the nine classes into.
Carried
What was open when a line began.
ClaimKind
The three ways a file’s name says what language it is. A whole name is answered before an extension, and the #! line only for a file that has neither.
CountingModel
Where the code and comment columns come from.
ExplainError
Why a file could not be explained.
LineClass
Which of the nine a single line was sorted into. One variant per field of LineClasses, named after it and described there.
RunError
A run that produced nothing at all, as opposed to a run that produced zeros.
ScanSkip
The head check that sets a file aside in a directory scan.
SettledBy
What decided a name that more than one language claimed.
SortCriterion
Which figure decides the order of a report’s rows.
SpanKind
What a Span holds.

Constants§

LANGUAGE_CONFLICTS_FILE_NAME
The name of the file that decides which language gets an extension or a file name two of them claim.
UNNAMED_MODULE_NAME
The name of the report row holding everything no target was given a name for.

Functions§

explain_file
Reads one file and answers for every line of it: which class it landed in, what earlier lines had left open, and which language’s rules read it.
prints_phase_timing
Whether this run will print a report of where its time went to the error output, which the MEZURA_PHASE_TIMING environment variable asks for.
run
Counts the directories and files the configuration names, and gives back the figures.
run_watched
The same run, for a caller that needs real time feedback while it happens.