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
use {
crate::{
control::{ControlFile, ControlParagraph},
error::{DebianError, Result},
},
std::io::BufRead,
};
#[derive(Default)]
pub struct SourcePackageControlFile<'a> {
general: ControlParagraph<'a>,
binaries: Vec<ControlParagraph<'a>>,
}
impl<'a> SourcePackageControlFile<'a> {
pub fn from_paragraphs(
mut paragraphs: impl Iterator<Item = ControlParagraph<'a>>,
) -> Result<Self> {
let general = paragraphs.next().ok_or_else(|| {
DebianError::ControlParseError(
"no general paragraph in source control file".to_string(),
)
})?;
let binaries = paragraphs.collect::<Vec<_>>();
Ok(Self { general, binaries })
}
pub fn parse_reader<R: BufRead>(reader: &mut R) -> Result<Self> {
let control = ControlFile::parse_reader(reader)?;
Self::from_paragraphs(control.paragraphs().map(|x| x.to_owned()))
}
pub fn parse_str(s: &str) -> Result<Self> {
let mut reader = std::io::BufReader::new(s.as_bytes());
Self::parse_reader(&mut reader)
}
pub fn general_paragraph(&self) -> &ControlParagraph<'a> {
&self.general
}
pub fn binary_paragraphs(&self) -> impl Iterator<Item = &ControlParagraph<'a>> {
self.binaries.iter()
}
}