Skip to main content

Crate reading_time

Crate reading_time 

Source
Expand description

§reading-time — estimate how long a text takes to read

Count the words in a text and estimate the reading time, with sensible handling of CJK characters (each counts as a word, and trailing punctuation is absorbed). A faithful Rust port of the widely-used reading-time npm package.

use reading_time::reading_time;

let result = reading_time("Hello world, this is a test.");
assert_eq!(result.words, 6);
assert_eq!(result.text, "1 min read");

Use reading_time_with to set the words-per-minute rate (default 200):

use reading_time::reading_time_with;
assert_eq!(reading_time_with(&"word ".repeat(400), 200).minutes, 2.0);

Zero dependencies. (Uses std for floating-point rounding.)

Structs§

ReadingTime
The result of a reading-time estimate.

Functions§

reading_time
Estimate the reading time of text at 200 words per minute.
reading_time_with
Estimate the reading time of text at words_per_minute (a value of 0 falls back to the default of 200, matching the reference).