text-statistics¶
How long is this text, how long will it take to read, and how hard is it? Count the words, sentences, and characters, average the lengths, divide by a reading speed, and blend the signals into a difficulty score — the numbers writing tools surface alongside every draft.
text-statistics is a pure-Rust, zero-dependency crate that computes all
of it in a single pass: word / sentence / character counts, average word and
sentence length, estimated reading time (seconds and minutes), and a 0–100
lexile-like difficulty estimate. It is the measurement engine behind the
BeLikeNative AI writing assistant, packaged as a
small library you can drop into editors, CLIs, and build pipelines.
What the numbers mean¶
| signal | meaning |
|---|---|
words |
whitespace/punctuation-delimited word tokens |
sentences |
., !, ? terminators (a trailing fragment still counts) |
characters |
total Unicode scalar values, including whitespace |
avg_word_length |
letters per word (digits excluded, so 12345 is neutral) |
estimated_reading_* |
seconds/minutes at 200 words per minute |
difficulty_score |
0–100 blend of word length and sentence length signals |
The difficulty bands derived from the score:
| band | score | style |
|---|---|---|
Easy |
0–32.99 | short words, short sentences |
Medium |
33–65.99 | typical adult prose |
Hard |
66–100 | long words or long sentences |
Install¶
Quick start¶
use text_statistics::{stats, Difficulty};
let s = stats("The cat sat on the mat. It was a good day for a nap.");
println!("words: {}", s.words); // 14
println!("sentences: {}", s.sentences); // 2
println!("chars: {}", s.characters);
println!("avg word: {:.1}", s.avg_word_length);
println!("read sec: {:.0}", s.estimated_reading_seconds);
println!("difficulty:{:.1}", s.difficulty_score);
println!("band: {:?}", s.difficulty_band()); // Easy
See it live
The crate gives you the numbers. For a live in-editor word count, reading time, and difficulty readout with rewrite suggestions, use the BeLikeNative writing assistant.
Features¶
- Pure Rust, no deps — a single file of arithmetic over the input, no features.
- Single-pass totals — counts, averages, reading time, and difficulty in one walk.
- Contractions kept whole —
don'tis one word, not two. - Digits don't inflate length — average word length counts letters only.
- Difficulty bands —
Difficultyenum +difficulty_band()for quick labels. - Deterministic — same input always yields identical output.
- MIT licensed — embed anywhere.
Links¶
- Source crate:
text-statistics - Interactive tool: BeLikeNative