Skip to content

Examples

Real-world text-statistics scenarios. Every example is runnable Rust; copy any block into a binary, or wire the same calls into the BeLikeNative writing assistant for a live in-editor readout.

1. Word count and reading time

Get the headline numbers a writing tool shows in its status bar.

use text_statistics::stats;

let s = stats("The cat sat on the mat. It was a good day for a nap.");
println!("words:   {}", s.words);
println!("minutes: {}", s.estimated_reading_minutes);

2. Difficulty band of a draft

Classify prose as easy / medium / hard before publishing.

use text_statistics::{stats, Difficulty};

let easy = stats("The cat sat on the mat. The dog ran. It was fun.");
let hard = stats(
    "Notwithstanding the fundamental institutional accommodations, the \
     multidisciplinary organizational representatives demonstrated extraordinary \
     quantitative methodological considerations throughout the deliberations.",
);

assert_eq!(easy.difficulty_band(), Difficulty::Easy);
assert_eq!(hard.difficulty_band(), Difficulty::Hard);

3. Compare average word length across drafts

Longer average word length signals denser vocabulary. Pick the simpler draft.

use text_statistics::stats;

let drafts = [
    "We need to test this method carefully.",
    "The implementation of the aforementioned methodology necessitates evaluation.",
];

let simplest = drafts
    .iter()
    .min_by(|a, b| {
        stats(a).avg_word_length
            .partial_cmp(&stats(b).avg_word_length)
            .unwrap()
    })
    .unwrap();
println!("simplest: {simplest}");

4. Character counts for length limits

Twitter-style or meta-description limits care about characters, including or excluding spaces.

use text_statistics::stats;

let s = stats("A concise meta description for search results.");
println!("total chars:   {}", s.characters);
println!("without space: {}", s.characters_no_spaces);

5. Empty input is safe

Zero words yields all-zero counts, zero difficulty, and Easy — never a panic.

use text_statistics::{stats, Difficulty};

let s = stats("");
assert_eq!(s.words, 0);
assert_eq!(s.difficulty_score, 0.0);
assert_eq!(s.difficulty_band(), Difficulty::Easy);

Next steps

For a live word count, reading time, and difficulty readout that updates as you type, with rewrite suggestions for dense passages, use the BeLikeNative AI writing assistant.