textstat
Readability metrics for English text. Flesch Reading Ease, Flesch-Kincaid
Grade, Gunning Fog, SMOG, Automated Readability Index, Coleman-Liau — plus the
word / sentence / syllable counts they're built on. Inspired by Python's
textstat. Zero dependencies, #![no_std].
let text = "The cat sat on the mat. The dog ran fast.";
assert_eq!; // words
assert_eq!;
assert_eq!;
let ease = flesch_reading_ease; // ~117 (very easy)
let grade = flesch_kincaid_grade; // ~ -1.8 (well below grade 1)
Why textstat?
Rust's readability crates are article extractors (arc90/Mozilla Readability) —
they pull the main content out of a web page. None of them compute readability
scores. textstat fills that gap: drop-in functions for the standard formulas,
useful for content tooling, SEO, writing assistants, education, and accessibility
(WCAG) checks.
Install
[]
= "0.1"
Metrics
| Function | Returns |
|---|---|
flesch_reading_ease |
0–100+ score (higher = easier) |
flesch_kincaid_grade |
U.S. school grade level |
gunning_fog |
U.S. school grade level |
smog_index |
U.S. school grade level |
automated_readability_index |
U.S. school grade level |
coleman_liau_index |
U.S. school grade level |
reading_time(text, wpm) |
estimated seconds to read |
Counts
lexicon_count (words), sentence_count, syllable_count, syllables(word),
polysyllabic_count, char_count (non-whitespace), letter_count.
Accuracy
Syllables are estimated with a fast English heuristic (vowel groups + a silent-e
rule, including accented Latin vowels), not a pronunciation dictionary, so scores
are close to — not bit-identical with — dictionary-based tools. The metric
formulas are the standard published ones.
sentence_countskips decimal points (3.14) and initialism dots (U.S.A.); trailing abbreviation dots (Dr.) may still add one.- Best results are on English text. Non-Latin scripts (no Latin vowels) fall back to one syllable per word, so scores stay bounded rather than correct.
- Empty input yields
0everywhere — no panics, no division by zero.
no_std
textstat is #![no_std] (needs only alloc) with a dependency-free Newton's
-method sqrt, so it builds for bare-metal targets such as thumbv7em-none-eabi.
License
Licensed under either of Apache-2.0 or MIT at your option.