unistore_progress/
config.rs

1//! 【配置】- 进度追踪器配置
2//!
3//! 职责:
4//! - 定义进度追踪器的配置选项
5//! - 提供合理的默认值
6
7use crate::deps::Duration;
8
9/// 进度追踪器配置
10#[derive(Debug, Clone)]
11pub struct ProgressConfig {
12    /// 订阅通道容量(默认 64)
13    pub channel_capacity: usize,
14
15    /// ETA 计算的最小样本数(默认 3)
16    pub eta_min_samples: usize,
17
18    /// ETA 平滑因子(0.0-1.0,默认 0.3)
19    /// 值越大,对最新速率的权重越高
20    pub eta_smoothing_factor: f64,
21
22    /// 自动完成阈值(当进度达到此比例时自动标记完成,默认 1.0)
23    pub auto_finish_threshold: f64,
24
25    /// 进度更新去抖动间隔(默认 50ms)
26    /// 在此间隔内的多次更新会合并为一次通知
27    pub debounce_interval: Duration,
28}
29
30impl Default for ProgressConfig {
31    fn default() -> Self {
32        Self {
33            channel_capacity: 64,
34            eta_min_samples: 3,
35            eta_smoothing_factor: 0.3,
36            auto_finish_threshold: 1.0,
37            debounce_interval: Duration::from_millis(50),
38        }
39    }
40}
41
42impl ProgressConfig {
43    /// 创建默认配置
44    pub fn new() -> Self {
45        Self::default()
46    }
47
48    /// 设置通道容量
49    pub fn channel_capacity(mut self, capacity: usize) -> Self {
50        self.channel_capacity = capacity;
51        self
52    }
53
54    /// 设置去抖动间隔
55    pub fn debounce_interval(mut self, interval: Duration) -> Self {
56        self.debounce_interval = interval;
57        self
58    }
59
60    /// 禁用去抖动(每次更新都通知)
61    pub fn no_debounce(mut self) -> Self {
62        self.debounce_interval = Duration::ZERO;
63        self
64    }
65}