estimate_with_speed

Function estimate_with_speed 

Source
pub fn estimate_with_speed(markdown: &str, speed: &ReadSpeed) -> ReadTime
Expand description

使用自定义速度配置估算阅读时间

使用指定的阅读速度配置来估算给定 Markdown 文本的阅读时间。

§Arguments

  • markdown - 需要估算阅读时间的 Markdown 文本
  • speed - 自定义的阅读速度配置

§Returns

返回包含阅读时间信息的 ReadTime 结构体。

§Examples

use markdown_readtime::{estimate_with_speed, ReadSpeed};

let markdown = "# Title\n\nThis is content";
let speed = ReadSpeed::default().wpm(180.0);
let read_time = estimate_with_speed(markdown, &speed);
println!("阅读需要 {} 时间", read_time.formatted);
Examples found in repository?
examples/custom_speed.rs (line 14)
3fn main() {
4    let markdown_content = "# 示例文章\n\n这是用来测试的文章内容。";
5
6    // 创建自定义阅读速度配置
7    let speed = ReadSpeed::default()
8        .wpm(180.0) // 设置每分钟阅读180个词
9        .image_time(15.0) // 每张图片额外增加15秒
10        .code_block_time(25.0) // 每个代码块额外增加25秒
11        .emoji(true) // 考虑emoji
12        .chinese(true); // 中文模式
13
14    let read_time = estimate_with_speed(markdown_content, &speed);
15    println!("自定义配置下的阅读时间: {}秒", read_time.total_seconds);
16}