Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update package_version.rs
- Added PostHead & PostHeader
- Finished Post Version Parsing
  • Loading branch information
Allstreamer committed Aug 10, 2022
commit 456228a9b73ebafa57b258df58070dc1b61864f3
53 changes: 49 additions & 4 deletions src/package_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ static VALIDATION_REGEX: &'static str = pomsky!(
)?
);

#[derive(Debug, Serialize, Deserialize)]
pub enum PostHead {
Post,
Rev,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PostHeader {
post_head: Option<PostHead>,
post_num: Option<u32>
}

#[derive(Debug, Serialize, Deserialize)]
pub enum PreHeader {
/// Present in 1.1alpha1 or 1.1a1 both are represented the same way
Expand All @@ -74,10 +86,11 @@ pub struct VersionRelease {

#[derive(Debug, Serialize, Deserialize)]
pub struct PackageVersion {
pub original: String,
epoch: Option<u32>,
release: VersionRelease,
pre: Option<PreHeader>,
post: Option<String>,
post: Option<PostHeader>,
dev: Option<String>,
local: Option<String>,
}
Expand Down Expand Up @@ -143,9 +156,40 @@ impl PackageVersion {
None => None,
};

// TODO!
let post: Option<String> = match version_match.name("post") {
Some(v) => Some(v.as_str().to_string()),
let post: Option<PostHeader> = match version_match.name("post") {
Some(_) => {
let post_num: Option<u32> = match version_match.name("post_n1") {
Some(v) => {
Some(v.as_str().parse::<u32>()?)
}
None => {
match version_match.name("post_n2") {
Some(v) => {
Some(v.as_str().parse::<u32>()?)
},
_ => None,
}
}
};

let post_head: Option<PostHead> = match version_match.name("post_l") {
Some(v) => {
match v.as_str() {
"post" => Some(PostHead::Post),
"rev" => Some(PostHead::Rev),
"r" => Some(PostHead::Rev),
// This branch Should be impossible (see regex-group post_l)
_ => None,
}
}
None => None
};

Some(PostHeader {
post_head,
post_num,
})
},
None => None,
};

Expand All @@ -162,6 +206,7 @@ impl PackageVersion {
};

Ok(Self {
original: version.to_string(),
epoch,
release,
pre,
Expand Down