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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::unit::Unit;
use std::time::SystemTime;
pub mod key;
mod utils;
#[cfg(feature = "progress-log")]
mod log;
#[cfg(feature = "progress-log")]
pub use self::log::Log;
#[doc(inline)]
pub use key::Key;
pub use utils::{Discard, DoOrDiscard, Either, ThroughputOnDrop};
pub type Step = usize;
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub enum State {
Blocked(&'static str, Option<SystemTime>),
Halted(&'static str, Option<SystemTime>),
Running,
}
impl Default for State {
fn default() -> Self {
State::Running
}
}
#[derive(Clone, Default, Debug)]
pub struct Value {
pub step: Step,
pub done_at: Option<Step>,
pub unit: Option<Unit>,
pub state: State,
}
impl Value {
pub fn fraction(&self) -> Option<f32> {
self.done_at.map(|done_at| self.step as f32 / done_at as f32)
}
}
#[derive(Clone, Default, Debug)]
pub struct Task {
pub name: String,
pub progress: Option<Value>,
}