arch_pkg_text/srcinfo/
field.rs1use strum::{AsRefStr, Display, EnumString, IntoStaticStr};
2
3#[derive(Debug, Clone, Copy, Eq, PartialEq)]
5pub struct Field<Name, Architecture> {
6 name: Name,
7 architecture: Option<Architecture>,
8}
9
10impl Field<(), ()> {
11 pub fn blank() -> Self {
16 Field {
17 name: (),
18 architecture: None,
19 }
20 }
21}
22
23impl<Name, Architecture> Field<Name, Architecture> {
24 pub fn with_name<NewName>(self, name: NewName) -> Field<NewName, Architecture> {
26 Field {
27 name,
28 architecture: self.architecture,
29 }
30 }
31
32 pub fn with_architecture<NewArchitecture>(
34 self,
35 architecture: Option<NewArchitecture>,
36 ) -> Field<Name, NewArchitecture> {
37 Field {
38 name: self.name,
39 architecture,
40 }
41 }
42
43 pub const fn name(&self) -> &'_ Name {
45 &self.name
46 }
47
48 pub const fn architecture(&self) -> Option<&'_ Architecture> {
50 self.architecture.as_ref()
51 }
52
53 pub fn into_components(self) -> (Name, Option<Architecture>) {
55 (self.name, self.architecture)
56 }
57}
58
59impl<'a, Architecture> Field<&'a str, Architecture> {
60 pub const fn name_str(&self) -> &'a str {
62 self.name()
63 }
64}
65
66impl<'a, Name> Field<Name, &'a str> {
67 pub fn architecture_str(&self) -> Option<&'a str> {
69 self.architecture().copied()
70 }
71}
72
73pub type RawField<'a> = Field<&'a str, &'a str>;
75
76pub type ParsedField<Architecture> = Field<FieldName, Architecture>;
78
79impl<Architecture> ParsedField<Architecture> {
80 pub fn name_str(&self) -> &'static str {
82 self.name().into()
83 }
84}
85
86impl<Architecture> From<FieldName> for ParsedField<Architecture> {
88 fn from(value: FieldName) -> Self {
89 Field::blank().with_name(value).with_architecture(None)
90 }
91}
92
93#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(AsRefStr, Display, EnumString, IntoStaticStr)] #[strum(use_phf)]
97pub enum FieldName {
98 #[strum(serialize = "pkgbase")]
100 Base,
101 #[strum(serialize = "pkgname")]
102 Name,
103
104 #[strum(serialize = "epoch")]
106 Epoch,
107 #[strum(serialize = "pkgrel")]
108 Release,
109 #[strum(serialize = "validpgpkeys")]
110 ValidPgpKeys,
111 #[strum(serialize = "pkgver")]
112 Version,
113
114 #[strum(serialize = "arch")]
116 Architecture,
117 #[strum(serialize = "backup")]
118 Backup,
119 #[strum(serialize = "changelog")]
120 ChangeLog,
121 #[strum(serialize = "pkgdesc")]
122 Description,
123 #[strum(serialize = "groups")]
124 Groups,
125 #[strum(serialize = "install")]
126 InstallScript,
127 #[strum(serialize = "license")]
128 License,
129 #[strum(serialize = "noextract")]
130 NoExtract,
131 #[strum(serialize = "options")]
132 Options,
133 #[strum(serialize = "source")]
134 Source,
135 #[strum(serialize = "url")]
136 Url,
137
138 #[strum(serialize = "depends")]
140 Dependencies,
141 #[strum(serialize = "checkdepends")]
142 CheckDependencies,
143 #[strum(serialize = "makedepends")]
144 MakeDependencies,
145 #[strum(serialize = "optdepends")]
146 OptionalDependencies,
147 #[strum(serialize = "provides")]
148 Provides,
149 #[strum(serialize = "conflicts")]
150 Conflicts,
151 #[strum(serialize = "replaces")]
152 Replaces,
153
154 #[strum(serialize = "md5sums")]
156 Md5Checksums,
157 #[strum(serialize = "sha1sums")]
158 Sha1Checksums,
159 #[strum(serialize = "sha224sums")]
160 Sha224Checksums,
161 #[strum(serialize = "sha256sums")]
162 Sha256Checksums,
163 #[strum(serialize = "sha384sums")]
164 Sha384Checksums,
165 #[strum(serialize = "sha512sums")]
166 Sha512Checksums,
167 #[strum(serialize = "b2sums")]
168 Blake2bChecksums,
169}
170
171mod parse;
172pub use parse::*;