1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Structured progress and operation tracking for CHD containers.
/// Operation phase being executed.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OperationPhase {
/// Examining / indexing parent units in differential CHD creation.
ExaminingParent,
/// Compressing hunks into the CHD container.
Compressing,
/// Extracting / decompressing data from a CHD container.
Extracting,
/// Verifying checksums across container hunks.
Verifying,
}
/// Status update emitted periodically during container operations.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProgressStatus {
/// The active operation phase.
pub phase: OperationPhase,
/// Progress counter (e.g. hunk index, byte offset, or frame index).
pub current: u64,
/// Total items or bytes expected in the operation.
pub total: u64,
/// Instantaneous or overall compression ratio [0.0..], if applicable.
pub ratio: Option<f64>,
}
impl ProgressStatus {
/// Creates a new progress status update.
pub const fn new(phase: OperationPhase, current: u64, total: u64, ratio: Option<f64>) -> Self {
Self {
phase,
current,
total,
ratio,
}
}
/// Computes completion percentage [0.0, 100.0].
pub fn percent(&self) -> f64 {
if self.total == 0 {
100.0
} else {
100.0 * (self.current as f64 / self.total as f64)
}
}
}