Add pluggable progressors

This commit is contained in:
2026-04-26 14:51:22 +02:00
parent c2ccccc88f
commit ce81e266b7
6 changed files with 182 additions and 61 deletions

42
src/progress/mod.rs Normal file
View File

@@ -0,0 +1,42 @@
pub mod log;
pub mod terminal;
pub trait Progressor: Send {
fn run(&mut self);
}
fn human_bytes(bytes: u64) -> String {
let units = ["B", "kB", "MB", "GB", "TB"];
let mut value = bytes as f64;
let mut index = 0;
while value >= 1024.0 && index < units.len() - 1 {
value /= 1024.0;
index += 1;
}
format!("{:.2} {:2}", value, units[index])
}
pub enum BackupEvent {
Estimate(u64),
StartingFullBackup {
source: String,
dest: String,
index: usize,
total: usize,
},
StartingIncrementalBackup {
source: String,
dest: String,
index: usize,
total: usize,
},
SnapshotCreated(String),
SnapshotDeleted(String),
BytesTransferred {
bytes: u64,
estimated_total: Option<u64>,
},
DatasetCompleted(String),
DryrunCompleted(String),
}