SlowScanConfig

Struct SlowScanConfig 

Source
pub struct SlowScanConfig { /* private fields */ }
Expand description

配置慢速扫描输出的参数

用于控制字符输出时的延迟行为,支持根据不同字符类型设置不同的延迟时间

§示例

use std::time::Duration;

use slow_scan_print::SlowScanConfig;

let config = SlowScanConfig::default()
    .set_base_delay(Duration::from_millis(30))
    .set_full_width_delay(Duration::from_millis(60));

Configuration parameters for slow scan output

Controls delay behavior during character output, with support for different delay times based on character type

Implementations§

Source§

impl SlowScanConfig

Source

pub fn base_delay(&self) -> &Duration

半角字符的基础延迟时间

适用于大多数拉丁字母、数字和符号


Base delay for half-width characters

Applies to most Latin letters, numbers and symbols

Source

pub fn full_width_delay(&self) -> &Duration

全角字符的延迟时间

适用于中文字符、日文字符、韩文字符等全角字符


Delay for full-width characters

Applies to Chinese, Japanese, Korean and other full-width characters

Source

pub fn control_char_delay(&self) -> &Duration

控制字符的延迟时间

适用于换行符(\n)、制表符(\t)等控制字符


Delay for control characters

Applies to control characters like newline(\n), tab(\t) etc.

Source

pub fn tail_delay(&self) -> &bool

是否在输出最后一个字符后也添加延迟

如果设置为 true,即使在输出最后一个字符后也会应用延迟 如果设置为 false,最后一个字符后不添加延迟


Whether to add delay after the last character output

If set to true, delay will be applied even after the last character If set to false, no delay is added after the last character

Source§

impl SlowScanConfig

Source

pub fn set_base_delay(&mut self, val: Duration) -> &mut Self

半角字符的基础延迟时间

适用于大多数拉丁字母、数字和符号


Base delay for half-width characters

Applies to most Latin letters, numbers and symbols

Source

pub fn set_full_width_delay(&mut self, val: Duration) -> &mut Self

全角字符的延迟时间

适用于中文字符、日文字符、韩文字符等全角字符


Delay for full-width characters

Applies to Chinese, Japanese, Korean and other full-width characters

Source

pub fn set_control_char_delay(&mut self, val: Duration) -> &mut Self

控制字符的延迟时间

适用于换行符(\n)、制表符(\t)等控制字符


Delay for control characters

Applies to control characters like newline(\n), tab(\t) etc.

Source

pub fn set_tail_delay(&mut self, val: bool) -> &mut Self

是否在输出最后一个字符后也添加延迟

如果设置为 true,即使在输出最后一个字符后也会应用延迟 如果设置为 false,最后一个字符后不添加延迟


Whether to add delay after the last character output

If set to true, delay will be applied even after the last character If set to false, no delay is added after the last character

Source§

impl SlowScanConfig

Source

pub fn set_base_delay_from_expected_total_duration( &mut self, expectation: Duration, chunk_count: u32, ) -> &mut Self

根据预期的总持续时间和块数量自动计算并设置基础延迟

这个方法适用于需要精确控制整体输出时长的场景,通过预期的总时长和 块数量来自动计算每个块之间的基础延迟时间。

§参数
  • expectation: 期望的总输出持续时间
  • chunk_count: 输出的块数量(字符块或字节块)
§计算规则
  • 如果 tail_delaytrue,延迟次数等于块数量
  • 如果 tail_delayfalse,延迟次数等于 块数量 - 1
  • 基础延迟 = 期望总时长 / 延迟次数
  • 如果块数量为 0,基础延迟设置为 Duration::ZERO
§示例
use std::time::Duration;

use slow_scan_print::SlowScanConfig;

// 希望在 1 秒内输出 10 个块
let mut config = SlowScanConfig::default();
config
    .set_tail_delay(true)
    .set_base_delay_from_expected_total_duration(
        Duration::from_secs(1),
        10
    );

assert_eq!(*config.base_delay(), Duration::from_millis(100));

config
    .set_tail_delay(false)
    .set_base_delay_from_expected_total_duration(
        Duration::from_secs(1),
        11
    );
assert_eq!(*config.base_delay(), Duration::from_millis(100));
§注意
  • 这个方法不会修改 full_width_delaycontrol_char_delay 的设置
  • 实际总时长可能因系统调度和性能而有微小偏差
  • 如果 chunk_count 为 0 或 1(且 tail_delayfalse),基础延迟会被设置为 0

Automatically calculates and sets base delay based on expected total duration and chunk count

This method is useful for scenarios requiring precise control over total output duration, automatically calculating the base delay between chunks based on expected total time and number of chunks.

§Arguments
  • expectation: Expected total output duration
  • chunk_count: Number of output chunks (character chunks or byte chunks)
§Calculation Rules
  • If tail_delay is true, number of delays equals chunk count
  • If tail_delay is false, number of delays equals chunk_count - 1
  • Base delay = Expected total duration / Number of delays
  • If chunk count is 0, base delay is set to Duration::ZERO
§Example
use std::time::Duration;

use slow_scan_print::SlowScanConfig;

// Want to output 10 chunks within 1 second
let mut config = SlowScanConfig::default();
config
    .set_tail_delay(true)
    .set_base_delay_from_expected_total_duration(
        Duration::from_secs(1),
        10
    );

assert_eq!(*config.base_delay(), Duration::from_millis(100));

config
    .set_tail_delay(false)
    .set_base_delay_from_expected_total_duration(
        Duration::from_secs(1),
        11
    );
assert_eq!(*config.base_delay(), Duration::from_millis(100));
§Notes
  • This method does not modify full_width_delay and control_char_delay settings
  • Actual total duration may have slight deviations due to system scheduling and performance
  • If chunk_count is 0 or 1 (and tail_delay is false), base delay will be set to 0

Trait Implementations§

Source§

impl Clone for SlowScanConfig

Source§

fn clone(&self) -> SlowScanConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SlowScanConfig

Source§

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

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

impl Default for SlowScanConfig

Source§

fn default() -> Self

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

impl Copy for SlowScanConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.