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]
|
||||
name = "updateinfo-xmlparser"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
18
src/lib.rs
18
src/lib.rs
|
@ -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 {
|
||||
|
@ -255,7 +263,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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user