unistore-progress 0.1.0

Progress tracking capability for UniStore
Documentation
//! 【配置】- 进度追踪器配置
//!
//! 职责:
//! - 定义进度追踪器的配置选项
//! - 提供合理的默认值

use crate::deps::Duration;

/// 进度追踪器配置
#[derive(Debug, Clone)]
pub struct ProgressConfig {
    /// 订阅通道容量(默认 64)
    pub channel_capacity: usize,

    /// ETA 计算的最小样本数(默认 3)
    pub eta_min_samples: usize,

    /// ETA 平滑因子(0.0-1.0,默认 0.3)
    /// 值越大,对最新速率的权重越高
    pub eta_smoothing_factor: f64,

    /// 自动完成阈值(当进度达到此比例时自动标记完成,默认 1.0)
    pub auto_finish_threshold: f64,

    /// 进度更新去抖动间隔(默认 50ms)
    /// 在此间隔内的多次更新会合并为一次通知
    pub debounce_interval: Duration,
}

impl Default for ProgressConfig {
    fn default() -> Self {
        Self {
            channel_capacity: 64,
            eta_min_samples: 3,
            eta_smoothing_factor: 0.3,
            auto_finish_threshold: 1.0,
            debounce_interval: Duration::from_millis(50),
        }
    }
}

impl ProgressConfig {
    /// 创建默认配置
    pub fn new() -> Self {
        Self::default()
    }

    /// 设置通道容量
    pub fn channel_capacity(mut self, capacity: usize) -> Self {
        self.channel_capacity = capacity;
        self
    }

    /// 设置去抖动间隔
    pub fn debounce_interval(mut self, interval: Duration) -> Self {
        self.debounce_interval = interval;
        self
    }

    /// 禁用去抖动(每次更新都通知)
    pub fn no_debounce(mut self) -> Self {
        self.debounce_interval = Duration::ZERO;
        self
    }
}