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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use std::marker;
use crate::raw;
use crate::util::Binding;
pub struct Progress<'a> {
pub(crate) raw: ProgressState,
pub(crate) _marker: marker::PhantomData<&'a raw::git_indexer_progress>,
}
pub(crate) enum ProgressState {
Borrowed(*const raw::git_indexer_progress),
Owned(raw::git_indexer_progress),
}
pub type IndexerProgress<'a> = dyn FnMut(Progress<'_>) -> bool + 'a;
impl<'a> Progress<'a> {
pub fn total_objects(&self) -> usize {
unsafe { (*self.raw()).total_objects as usize }
}
pub fn indexed_objects(&self) -> usize {
unsafe { (*self.raw()).indexed_objects as usize }
}
pub fn received_objects(&self) -> usize {
unsafe { (*self.raw()).received_objects as usize }
}
pub fn local_objects(&self) -> usize {
unsafe { (*self.raw()).local_objects as usize }
}
pub fn total_deltas(&self) -> usize {
unsafe { (*self.raw()).total_deltas as usize }
}
pub fn indexed_deltas(&self) -> usize {
unsafe { (*self.raw()).indexed_deltas as usize }
}
pub fn received_bytes(&self) -> usize {
unsafe { (*self.raw()).received_bytes as usize }
}
pub fn to_owned(&self) -> Progress<'static> {
Progress {
raw: ProgressState::Owned(unsafe { *self.raw() }),
_marker: marker::PhantomData,
}
}
}
impl<'a> Binding for Progress<'a> {
type Raw = *const raw::git_indexer_progress;
unsafe fn from_raw(raw: *const raw::git_indexer_progress) -> Progress<'a> {
Progress {
raw: ProgressState::Borrowed(raw),
_marker: marker::PhantomData,
}
}
fn raw(&self) -> *const raw::git_indexer_progress {
match self.raw {
ProgressState::Borrowed(raw) => raw,
ProgressState::Owned(ref raw) => raw as *const _,
}
}
}
#[deprecated(
since = "0.11.0",
note = "renamed to `IndexerProgress` to match upstream"
)]
#[allow(dead_code)]
pub type TransportProgress<'a> = IndexerProgress<'a>;