#[derive(Debug, Clone)]
pub struct ProgressConfig {
pub total: Option<u64>,
pub style: ProgressStyle,
}
impl ProgressConfig {
pub fn new(style: ProgressStyle) -> Self {
Self { total: None, style }
}
pub fn with_total(mut self, total: u64) -> Self {
self.total = Some(total);
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProgressStyle {
Bytes,
Count,
}
impl Default for ProgressStyle {
fn default() -> Self {
Self::Count
}
}
impl std::fmt::Display for ProgressStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Bytes => write!(f, "bytes"),
Self::Count => write!(f, "count"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_progress_config_construction() {
let config = ProgressConfig::new(ProgressStyle::Bytes);
assert_eq!(config.style, ProgressStyle::Bytes);
assert_eq!(config.total, None);
}
#[test]
fn test_progress_config_with_total() {
let config = ProgressConfig::new(ProgressStyle::Count).with_total(100);
assert_eq!(config.total, Some(100));
}
#[test]
fn test_progress_style_default() {
assert_eq!(ProgressStyle::default(), ProgressStyle::Count);
}
#[test]
fn test_progress_style_display() {
assert_eq!(format!("{}", ProgressStyle::Bytes), "bytes");
assert_eq!(format!("{}", ProgressStyle::Count), "count");
}
#[test]
fn test_progress_config_clone() {
let config = ProgressConfig::new(ProgressStyle::Count).with_total(50);
let cloned = config.clone();
assert_eq!(cloned.style, config.style);
assert_eq!(cloned.total, config.total);
}
}