arch_pkg_text/srcinfo/
field.rsuse strum::{AsRefStr, Display, EnumString, IntoStaticStr};
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Field<Name, Architecture> {
name: Name,
architecture: Option<Architecture>,
}
impl Field<(), ()> {
pub fn blank() -> Self {
Field {
name: (),
architecture: None,
}
}
}
impl<Name, Architecture> Field<Name, Architecture> {
pub fn with_name<NewName>(self, name: NewName) -> Field<NewName, Architecture> {
Field {
name,
architecture: self.architecture,
}
}
pub fn with_architecture<NewArchitecture>(
self,
architecture: Option<NewArchitecture>,
) -> Field<Name, NewArchitecture> {
Field {
name: self.name,
architecture,
}
}
pub const fn name(&self) -> &'_ Name {
&self.name
}
pub const fn architecture(&self) -> Option<&'_ Architecture> {
self.architecture.as_ref()
}
pub fn into_components(self) -> (Name, Option<Architecture>) {
(self.name, self.architecture)
}
}
impl<'a, Architecture> Field<&'a str, Architecture> {
pub const fn name_str(&self) -> &'a str {
self.name()
}
}
impl<'a, Name> Field<Name, &'a str> {
pub fn architecture_str(&self) -> Option<&'a str> {
self.architecture().copied()
}
}
pub type RawField<'a> = Field<&'a str, &'a str>;
pub type ParsedField<Architecture> = Field<FieldName, Architecture>;
impl<Architecture> ParsedField<Architecture> {
pub fn name_str(&self) -> &'static str {
self.name().into()
}
}
impl<Architecture> From<FieldName> for ParsedField<Architecture> {
fn from(value: FieldName) -> Self {
Field::blank().with_name(value).with_architecture(None)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(AsRefStr, Display, EnumString, IntoStaticStr)] #[strum(use_phf)]
pub enum FieldName {
#[strum(serialize = "pkgbase")]
Base,
#[strum(serialize = "pkgname")]
Name,
#[strum(serialize = "epoch")]
Epoch,
#[strum(serialize = "pkgrel")]
Release,
#[strum(serialize = "validpgpkeys")]
ValidPgpKeys,
#[strum(serialize = "pkgver")]
Version,
#[strum(serialize = "arch")]
Architecture,
#[strum(serialize = "backup")]
Backup,
#[strum(serialize = "changelog")]
ChangeLog,
#[strum(serialize = "pkgdesc")]
Description,
#[strum(serialize = "groups")]
Groups,
#[strum(serialize = "install")]
InstallScript,
#[strum(serialize = "license")]
License,
#[strum(serialize = "noextract")]
NoExtract,
#[strum(serialize = "options")]
Options,
#[strum(serialize = "source")]
Source,
#[strum(serialize = "url")]
Url,
#[strum(serialize = "depends")]
Dependencies,
#[strum(serialize = "checkdepends")]
CheckDependencies,
#[strum(serialize = "makedepends")]
MakeDependencies,
#[strum(serialize = "optdepends")]
OptionalDependencies,
#[strum(serialize = "provides")]
Provides,
#[strum(serialize = "conflicts")]
Conflicts,
#[strum(serialize = "replaces")]
Replaces,
#[strum(serialize = "md5sums")]
Md5Checksums,
#[strum(serialize = "sha1sums")]
Sha1Checksums,
#[strum(serialize = "sha224sums")]
Sha224Checksums,
#[strum(serialize = "sha256sums")]
Sha256Checksums,
#[strum(serialize = "sha384sums")]
Sha384Checksums,
#[strum(serialize = "sha512sums")]
Sha512Checksums,
#[strum(serialize = "b2sums")]
Blake2bChecksums,
}
mod parse;
pub use parse::*;