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
use {
crate::debian_source_control::DebianSourceControlFile,
std::ops::{Deref, DerefMut},
};
#[derive(Default)]
pub struct DebianSourcePackageList<'a> {
packages: Vec<DebianSourceControlFile<'a>>,
}
impl<'a> Deref for DebianSourcePackageList<'a> {
type Target = Vec<DebianSourceControlFile<'a>>;
fn deref(&self) -> &Self::Target {
&self.packages
}
}
impl<'a> DerefMut for DebianSourcePackageList<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.packages
}
}
impl<'a> IntoIterator for DebianSourcePackageList<'a> {
type Item = DebianSourceControlFile<'a>;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.packages.into_iter()
}
}
impl<'a> DebianSourcePackageList<'a> {
pub fn iter_with_package_name(
&self,
package: String,
) -> impl Iterator<Item = &DebianSourceControlFile<'a>> {
self.packages.iter().filter(
move |cf| matches!(cf.required_field_str("Package"), Ok(name) if name == package),
)
}
pub fn iter_with_binary_package(
&self,
package: String,
) -> impl Iterator<Item = &DebianSourceControlFile<'a>> {
self.packages.iter().filter(move |cf| {
if let Some(mut packages) = cf.binary() {
packages.any(|p| p == package)
} else {
false
}
})
}
pub fn iter_with_architecture(
&self,
architecture: String,
) -> impl Iterator<Item = &DebianSourceControlFile<'a>> {
self.packages.iter().filter(move |cf| {
if let Some(mut architectures) = cf.architecture() {
architectures.any(|a| a == architecture)
} else {
false
}
})
}
}