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
pub struct SilentProgressBar {
count: u64,
total: u64,
}
impl SilentProgressBar {
#[inline]
#[must_use]
pub fn new(total: u64) -> Self {
debug_assert!(total > 0);
Self { count: 0, total }
}
#[inline]
pub fn block(&mut self, size: u64) -> Option<(u64, u64)> {
debug_assert!(size > 0);
if self.count >= self.total {
None
} else {
let remaining = self.total - self.count;
let alloc = size.min(remaining);
let start = self.count;
let end = start + alloc;
self.count += alloc;
Some((start, end))
}
}
#[inline]
#[must_use]
pub const fn is_done(&self) -> bool {
self.count >= self.total
}
}