ReadSpeed

Struct ReadSpeed 

Source
pub struct ReadSpeed {
    pub words_per_minute: f64,
    pub seconds_per_image: f64,
    pub seconds_per_code_block: f64,
    pub count_emoji: bool,
    pub chinese: bool,
}
Expand description

阅读速度配置

允许自定义各种影响阅读时间的因素。

§Examples

use markdown_readtime::ReadSpeed;

// 使用构建器模式创建自定义配置
let speed = ReadSpeed::default()
    .wpm(180.0)
    .image_time(15.0)
    .code_block_time(25.0)
    .emoji(false);

// 或者直接创建
let speed = ReadSpeed::new(180.0, 15.0, 25.0, false, true);

Fields§

§words_per_minute: f64

每分钟阅读单词数(默认:200)

这是阅读速度的核心参数,用于计算文本的基础阅读时间。

§seconds_per_image: f64

每张图片额外时间(秒,默认:12)

每发现一张图片就会增加相应的时间,因为读者通常需要额外时间查看图片。

§seconds_per_code_block: f64

每个代码块额外时间(秒,默认:20)

每发现一个代码块就会增加相应的时间,因为代码通常需要更仔细的阅读。

§count_emoji: bool

是否考虑emoji(默认:true)

当启用时,emoji 会被单独计数,影响总的阅读时间估算。

§chinese: bool

是否中文(默认:true)

决定使用哪种文本计数方式:

  • true: 使用中文计数方式(计算字符数)
  • false: 使用英文计数方式(计算单词数)

Implementations§

Source§

impl ReadSpeed

Source

pub fn new( wpm: f64, seconds_per_image: f64, seconds_per_code_block: f64, count_emoji: bool, chinese: bool, ) -> Self

Source

pub fn wpm(self, wpm: f64) -> Self

Examples found in repository?
examples/custom_speed.rs (line 8)
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}
Source

pub fn image_time(self, seconds: f64) -> Self

Examples found in repository?
examples/custom_speed.rs (line 9)
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}
Source

pub fn code_block_time(self, seconds: f64) -> Self

Examples found in repository?
examples/custom_speed.rs (line 10)
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}
Source

pub fn emoji(self, count: bool) -> Self

Examples found in repository?
examples/custom_speed.rs (line 11)
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}
Source

pub fn chinese(self, is_chinese: bool) -> Self

Examples found in repository?
examples/custom_speed.rs (line 12)
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}

Trait Implementations§

Source§

impl Clone for ReadSpeed

Source§

fn clone(&self) -> ReadSpeed

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReadSpeed

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ReadSpeed

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for ReadSpeed

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.