update: 0.1.2

1. RpmInfo epoch 使用 Option<i32> 类型存储
2. arch() 返回 Option<&str>

Signed-off-by: Jia Chao <jiac13@chinaunicom.cn>
This commit is contained in:
Jia Chao 2024-09-18 10:22:39 +08:00
parent 2ad39b2a67
commit 6da497c4a5
2 changed files with 20 additions and 8 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "updateinfo-xmlparser"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
[dependencies]

View File

@ -181,7 +181,7 @@ pub struct RpmInfo {
// 包名
name: String,
// 可能为空
epoch: String,
epoch: Option<i32>,
version: String,
@ -198,7 +198,7 @@ impl RpmInfo {
pub fn new() -> Self {
RpmInfo {
name: String::new(),
epoch: String::new(),
epoch: None,
version: String::new(),
release: String::new(),
arch: String::new(),
@ -211,7 +211,12 @@ impl RpmInfo {
pub fn set(&mut self, key: &str, value: String) {
match key {
"name" => self.name = value,
"epoch" => self.epoch = value,
"epoch" => {
self.epoch = match value.parse::<i32>() {
Ok(i) => Some(i),
Err(_) => None,
};
},
"version" => self.version = value,
"release" => self.release = value,
"arch" => self.arch = value,
@ -225,12 +230,15 @@ impl RpmInfo {
&self.name
}
pub fn epoch(&self) -> Option<&str> {
pub fn epoch(&self) -> Option<i32> {
/*
if self.epoch != "" {
Some(&self.epoch)
} else {
None
}
*/
self.epoch
}
pub fn version(&self) -> &str {
@ -241,8 +249,12 @@ impl RpmInfo {
&self.release
}
pub fn arch(&self) -> &str {
&self.arch
pub fn arch(&self) -> Option<&str> {
if self.arch != "" {
Some(&self.arch)
} else {
None
}
}
pub fn file(&self) -> &str {
@ -255,7 +267,7 @@ impl RpmInfo {
pub fn evr(&self) -> String {
if self.epoch().is_some() {
format!("{}:{}-{}", self.epoch, self.version, self.release)
format!("{}:{}-{}", self.epoch.as_ref().unwrap(), self.version, self.release)
} else {
format!("{}-{}", self.version, self.release)
}