arch_pkg_text/desc/
field.rs

1use derive_more::{AsRef, Deref};
2use strum::{AsRefStr, Display, EnumString, IntoStaticStr};
3
4/// Field of a `desc` file.
5#[derive(Debug, Clone, Copy, Eq, PartialEq)] // core traits
6#[derive(AsRef, Deref, derive_more::Display)] // derive_more traits
7#[display("%{_0}%")]
8pub struct Field<Name>(Name);
9
10impl<Name> Field<Name> {
11    /// Get an immutable reference to the name of the field.
12    pub const fn name(&self) -> &'_ Name {
13        &self.0
14    }
15
16    /// Convert into the name of the field.
17    pub fn into_name(self) -> Name {
18        self.0
19    }
20}
21
22/// Raw string field of a `desc` file.
23pub type RawField<'a> = Field<&'a str>;
24
25impl<'a> RawField<'a> {
26    /// Get the name of the field as a string slice.
27    pub const fn name_str(&self) -> &'a str {
28        self.name()
29    }
30}
31
32/// Parsed field of a `desc` file.
33pub type ParsedField = Field<FieldName>;
34
35impl ParsedField {
36    /// Create a new [`ParsedField`].
37    pub const fn new(name: FieldName) -> Self {
38        Field(name)
39    }
40
41    /// Get the name of the field as a string slice.
42    pub fn name_str(&self) -> &'static str {
43        self.name().into()
44    }
45}
46
47impl From<FieldName> for ParsedField {
48    fn from(value: FieldName) -> Self {
49        ParsedField::new(value)
50    }
51}
52
53/// Field name of a `desc` file.
54#[derive(Debug, Clone, Copy, PartialEq, Eq)] // core traits
55#[derive(AsRefStr, Display, EnumString, IntoStaticStr)] // strum traits
56#[strum(use_phf)]
57pub enum FieldName {
58    #[strum(serialize = "FILENAME")]
59    FileName,
60    #[strum(serialize = "NAME")]
61    Name,
62    #[strum(serialize = "BASE")]
63    Base,
64    #[strum(serialize = "VERSION")]
65    Version,
66    #[strum(serialize = "DESC")]
67    Description,
68    #[strum(serialize = "GROUPS")]
69    Groups,
70    #[strum(serialize = "CSIZE")]
71    CompressedSize,
72    #[strum(serialize = "ISIZE")]
73    InstalledSize,
74    #[strum(serialize = "MD5SUM")]
75    Md5Checksum,
76    #[strum(serialize = "SHA256SUM")]
77    Sha256Checksum,
78    #[strum(serialize = "PGPSIG")]
79    PgpSignature,
80    #[strum(serialize = "URL")]
81    Url,
82    #[strum(serialize = "LICENSE")]
83    License,
84    #[strum(serialize = "ARCH")]
85    Architecture,
86    #[strum(serialize = "BUILDDATE")]
87    BuildDate,
88    #[strum(serialize = "PACKAGER")]
89    Packager,
90    #[strum(serialize = "DEPENDS")]
91    Dependencies,
92    #[strum(serialize = "MAKEDEPENDS")]
93    MakeDependencies,
94    #[strum(serialize = "CHECKDEPENDS")]
95    CheckDependencies,
96    #[strum(serialize = "OPTDEPENDS")]
97    OptionalDependencies,
98    #[strum(serialize = "PROVIDES")]
99    Provides,
100    #[strum(serialize = "CONFLICTS")]
101    Conflicts,
102    #[strum(serialize = "REPLACES")]
103    Replaces,
104}
105
106mod parse;
107pub use parse::*;