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
#[derive(Debug, Serialize, Deserialize)]
pub struct MatrixElement {
finished_at: Option<String>,
result: Option<u32>,
number: String,
id: Option<u32>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Matrix {
id: u32,
matrix: Vec<MatrixElement>,
}
impl MatrixElement {
pub fn id(&self) -> u32 {
self.id.unwrap()
}
pub fn is_leader(&self) -> bool {
super::is_leader(&self.number)
}
pub fn is_succeeded(&self) -> bool {
if !self.is_finished() {
return false;
}
match self.result {
None => false,
Some(0) => true,
Some(_) => false,
}
}
pub fn is_finished(&self) -> bool {
self.finished_at.is_some()
}
}
impl Matrix {
pub fn builds(&self) -> &[MatrixElement] {
&self.matrix
}
pub fn others_finished(&self) -> bool {
self.matrix.iter()
.filter(|build| !build.is_leader())
.all(|build| build.is_finished())
}
pub fn others_succeeded(&self) -> bool {
self.matrix.iter()
.filter(|build| !build.is_leader())
.all(|build| build.is_succeeded())
}
}