arch_pkg_text/desc/
field.rs

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use derive_more::{AsRef, Deref};
use strum::{AsRefStr, Display, EnumString, IntoStaticStr};

/// Field of a `desc` file.
#[derive(Debug, Clone, Copy, Eq, PartialEq)] // core traits
#[derive(AsRef, Deref, derive_more::Display)] // derive_more traits
#[display("%{_0}%")]
pub struct Field<Name>(Name);

impl<Name> Field<Name> {
    /// Get an immutable reference to the name of the field.
    pub const fn name(&self) -> &'_ Name {
        &self.0
    }

    /// Convert into the name of the field.
    pub fn into_name(self) -> Name {
        self.0
    }
}

/// Raw string field of a `desc` file.
pub type RawField<'a> = Field<&'a str>;

impl<'a> RawField<'a> {
    /// Get the name of the field as a string slice.
    pub const fn name_str(&self) -> &'a str {
        self.name()
    }
}

/// Parsed field of a `desc` file.
pub type ParsedField = Field<FieldName>;

impl ParsedField {
    /// Create a new [`ParsedField`].
    pub const fn new(name: FieldName) -> Self {
        Field(name)
    }

    /// Get the name of the field as a string slice.
    pub fn name_str(&self) -> &'static str {
        self.name().into()
    }
}

impl From<FieldName> for ParsedField {
    fn from(value: FieldName) -> Self {
        ParsedField::new(value)
    }
}

/// Field name of a `desc` file.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] // core traits
#[derive(AsRefStr, Display, EnumString, IntoStaticStr)] // strum traits
#[strum(use_phf)]
pub enum FieldName {
    #[strum(serialize = "FILENAME")]
    FileName,
    #[strum(serialize = "NAME")]
    Name,
    #[strum(serialize = "BASE")]
    Base,
    #[strum(serialize = "VERSION")]
    Version,
    #[strum(serialize = "DESC")]
    Description,
    #[strum(serialize = "GROUPS")]
    Groups,
    #[strum(serialize = "CSIZE")]
    CompressedSize,
    #[strum(serialize = "ISIZE")]
    InstalledSize,
    #[strum(serialize = "MD5SUM")]
    Md5Checksum,
    #[strum(serialize = "SHA256SUM")]
    Sha256Checksum,
    #[strum(serialize = "PGPSIG")]
    PgpSignature,
    #[strum(serialize = "URL")]
    Url,
    #[strum(serialize = "LICENSE")]
    License,
    #[strum(serialize = "ARCH")]
    Architecture,
    #[strum(serialize = "BUILDDATE")]
    BuildDate,
    #[strum(serialize = "PACKAGER")]
    Packager,
    #[strum(serialize = "DEPENDS")]
    Dependencies,
    #[strum(serialize = "MAKEDEPENDS")]
    MakeDependencies,
    #[strum(serialize = "CHECKDEPENDS")]
    CheckDependencies,
    #[strum(serialize = "OPTDEPENDS")]
    OptionalDependencies,
    #[strum(serialize = "PROVIDES")]
    Provides,
    #[strum(serialize = "CONFLICTS")]
    Conflicts,
    #[strum(serialize = "REPLACES")]
    Replaces,
}

mod parse;
pub use parse::*;