Skip to main content

debian_control/lossy/
ftpmaster.rs

1//! FTP-master-related files
2
3use deb822_fast::{FromDeb822, FromDeb822Paragraph, ToDeb822};
4
5fn serialize_list(list: &[String]) -> String {
6    list.join("\n")
7}
8
9fn deserialize_list(list: &str) -> Result<Vec<String>, String> {
10    Ok(list.lines().map(|s| s.to_string()).collect())
11}
12
13#[derive(Debug, Clone, FromDeb822, ToDeb822)]
14/// A removal file
15pub struct Removal {
16    #[deb822(field = "Date")]
17    /// The date of the removal
18    pub date: String,
19
20    #[deb822(field = "Suite")]
21    /// The suite from which the package was removed
22    pub suite: Option<String>,
23
24    #[deb822(field = "Ftpmaster")]
25    /// The FTP-master who performed the removal
26    pub ftpmaster: String,
27
28    #[deb822(field = "Sources", serialize_with = serialize_list, deserialize_with = deserialize_list)]
29    /// The sources that were removed
30    pub sources: Option<Vec<String>>,
31
32    #[deb822(field = "Binaries", serialize_with = serialize_list, deserialize_with = deserialize_list)]
33    /// The binaries that were removed
34    pub binaries: Option<Vec<String>>,
35
36    #[deb822(field = "Reason")]
37    /// The reason for the removal
38    pub reason: String,
39
40    #[deb822(field = "Bug")]
41    /// The bug number associated with the removal
42    pub bug: Option<u32>,
43}
44
45impl std::str::FromStr for Removal {
46    type Err = String;
47
48    fn from_str(s: &str) -> Result<Self, Self::Err> {
49        let paragraph = deb822_fast::Paragraph::from_str(s).map_err(|e| e.to_string())?;
50        Self::from_paragraph(&paragraph).map_err(|e| e.to_string())
51    }
52}