debian_packaging/
source_package_control.rs1use {
8 crate::{
9 control::{ControlFile, ControlParagraph},
10 error::{DebianError, Result},
11 },
12 std::io::BufRead,
13};
14
15#[derive(Default)]
22pub struct SourcePackageControlFile<'a> {
23 general: ControlParagraph<'a>,
24 binaries: Vec<ControlParagraph<'a>>,
25}
26
27impl<'a> SourcePackageControlFile<'a> {
28 pub fn from_paragraphs(
30 mut paragraphs: impl Iterator<Item = ControlParagraph<'a>>,
31 ) -> Result<Self> {
32 let general = paragraphs.next().ok_or_else(|| {
33 DebianError::ControlParseError(
34 "no general paragraph in source control file".to_string(),
35 )
36 })?;
37
38 let binaries = paragraphs.collect::<Vec<_>>();
39
40 Ok(Self { general, binaries })
41 }
42
43 pub fn parse_reader<R: BufRead>(reader: &mut R) -> Result<Self> {
45 let control = ControlFile::parse_reader(reader)?;
46
47 Self::from_paragraphs(control.paragraphs().map(|x| x.to_owned()))
48 }
49
50 pub fn parse_str(s: &str) -> Result<Self> {
52 let mut reader = std::io::BufReader::new(s.as_bytes());
53 Self::parse_reader(&mut reader)
54 }
55
56 pub fn general_paragraph(&self) -> &ControlParagraph<'a> {
58 &self.general
59 }
60
61 pub fn binary_paragraphs(&self) -> impl Iterator<Item = &ControlParagraph<'a>> {
63 self.binaries.iter()
64 }
65}