update: 0.1.2 RpmInfo epoch 使用 Option<i32> 类型存储
Signed-off-by: Jia Chao <jiac13@chinaunicom.cn>
This commit is contained in:
parent
2ad39b2a67
commit
5411d33316
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "updateinfo-xmlparser"
|
name = "updateinfo-xmlparser"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
18
src/lib.rs
18
src/lib.rs
|
@ -181,7 +181,7 @@ pub struct RpmInfo {
|
||||||
// 包名
|
// 包名
|
||||||
name: String,
|
name: String,
|
||||||
// 可能为空
|
// 可能为空
|
||||||
epoch: String,
|
epoch: Option<i32>,
|
||||||
|
|
||||||
version: String,
|
version: String,
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ impl RpmInfo {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
RpmInfo {
|
RpmInfo {
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
epoch: String::new(),
|
epoch: None,
|
||||||
version: String::new(),
|
version: String::new(),
|
||||||
release: String::new(),
|
release: String::new(),
|
||||||
arch: String::new(),
|
arch: String::new(),
|
||||||
|
@ -211,7 +211,12 @@ impl RpmInfo {
|
||||||
pub fn set(&mut self, key: &str, value: String) {
|
pub fn set(&mut self, key: &str, value: String) {
|
||||||
match key {
|
match key {
|
||||||
"name" => self.name = value,
|
"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,
|
"version" => self.version = value,
|
||||||
"release" => self.release = value,
|
"release" => self.release = value,
|
||||||
"arch" => self.arch = value,
|
"arch" => self.arch = value,
|
||||||
|
@ -225,12 +230,15 @@ impl RpmInfo {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn epoch(&self) -> Option<&str> {
|
pub fn epoch(&self) -> Option<i32> {
|
||||||
|
/*
|
||||||
if self.epoch != "" {
|
if self.epoch != "" {
|
||||||
Some(&self.epoch)
|
Some(&self.epoch)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
self.epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn version(&self) -> &str {
|
pub fn version(&self) -> &str {
|
||||||
|
@ -255,7 +263,7 @@ impl RpmInfo {
|
||||||
|
|
||||||
pub fn evr(&self) -> String {
|
pub fn evr(&self) -> String {
|
||||||
if self.epoch().is_some() {
|
if self.epoch().is_some() {
|
||||||
format!("{}:{}-{}", self.epoch, self.version, self.release)
|
format!("{}:{}-{}", self.epoch.as_ref().unwrap(), self.version, self.release)
|
||||||
} else {
|
} else {
|
||||||
format!("{}-{}", self.version, self.release)
|
format!("{}-{}", self.version, self.release)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user