Add arch
field to Package
This commit is contained in:
parent
90b163eb1b
commit
a58150cc9c
56
src/package/arch.rs
Normal file
56
src/package/arch.rs
Normal file
@ -0,0 +1,56 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{fmt, str::FromStr, error::Error};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum Arch {
|
||||
armv7l,
|
||||
aarch64,
|
||||
i486,
|
||||
i586,
|
||||
i686,
|
||||
riscv64,
|
||||
#[default]
|
||||
x86_64,
|
||||
}
|
||||
|
||||
impl fmt::Display for Arch {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", match self {
|
||||
Self::armv7l => "armv7l",
|
||||
Self::aarch64 => "aarch64",
|
||||
Self::i486 => "i486",
|
||||
Self::i586 => "i586",
|
||||
Self::i686 => "i686",
|
||||
Self::riscv64 => "riscv64",
|
||||
Self::x86_64 => "x86_64",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParseArchError;
|
||||
|
||||
impl fmt::Display for ParseArchError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "error parsing architecture")
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ParseArchError {}
|
||||
|
||||
impl FromStr for Arch {
|
||||
type Err = ParseArchError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"i486" | "x86" => Ok(Self::i486),
|
||||
"i586" => Ok(Self::i586),
|
||||
"i686" => Ok(Self::i686),
|
||||
"armv7l" | "arm" => Ok(Self::armv7l),
|
||||
"arm64" | "aarch64" | "armv8" => Ok(Self::aarch64),
|
||||
"riscv" | "riscv64" => Ok(Self::riscv64),
|
||||
_ => Err(ParseArchError)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
mod arch;
|
||||
mod dependency;
|
||||
mod specs;
|
||||
|
||||
@ -15,7 +16,7 @@ use {
|
||||
crate::tar::{Node, Owner},
|
||||
};
|
||||
|
||||
pub use {dependency::Dependency, specs::Specs};
|
||||
pub use {arch::Arch, dependency::Dependency, specs::Specs};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct User {
|
||||
@ -36,6 +37,8 @@ pub struct Package {
|
||||
pub name: String,
|
||||
/// The `Version` of the package
|
||||
pub version: Version,
|
||||
/// The architecture the package is built for
|
||||
pub arch: Arch,
|
||||
/// The release number for this package
|
||||
pub release: u8,
|
||||
/// a single line description of the package
|
||||
@ -110,7 +113,7 @@ impl Package {
|
||||
|
||||
/// Returns the formatted full package name including version and release strings
|
||||
pub fn fullname(&self) -> String {
|
||||
format!("{}-{}_{}", self.name, self.version, self.release)
|
||||
format!("{}-{}_{}{}", self.name, self.version, self.arch, self.release)
|
||||
}
|
||||
|
||||
/// Tests whether this package is an update for another
|
||||
|
Loading…
Reference in New Issue
Block a user