10000 Update package_version.rs · Allstreamer/rust-pip@456228a · GitHub
[go: up one dir, main page]

Skip to content

Commit 456228a

Browse files
committed
Update package_version.rs
- Added PostHead & PostHeader - Finished Post Version Parsing
1 parent a894426 commit 456228a

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

src/package_version.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ static VALIDATION_REGEX: &'static str = pomsky!(
5151
)?
5252
);
5353

54+
#[derive(Debug, Serialize, Deserialize)]
55+
pub enum PostHead {
56+
Post,
57+
Rev,
58+
}
59+
60+
#[derive(Debug, Serialize, Deserialize)]
61+
pub struct PostHeader {
62+
post_head: Option<PostHead>,
63+
post_num: Option<u32>
64+
}
65+
5466
#[derive(Debug, Serialize, Deserialize)]
5567
pub enum PreHeader {
5668
/// Present in 1.1alpha1 or 1.1a1 both are represented the same way
@@ -74,10 +86,11 @@ pub struct VersionRelease {
7486

7587
#[derive(Debug, Serialize, Deserialize)]
7688
pub struct PackageVersion {
89+
pub original: String,
7790
epoch: Option<u32>,
7891
release: VersionRelease,
7992
pre: Option<PreHeader>,
80-
post: Option<String>,
93+
post: Option<PostHeader>,
8194
dev: Option<String>,
8295
local: Option<String>,
8396
}
@@ -143,9 +156,40 @@ impl PackageVersion {
143156
None => None,
144157
};
145158

146-
// TODO!
147-
let post: Option<String> = match version_match.name("post") {
148-
Some(v) => Some(v.as_str().to_string()),
159+
let post: Option<PostHeader> = match version_match.name("post") {
160+
Some(_) => {
161+
let post_num: Option<u32> = match version_match.name("post_n1") {
162+
Some(v) => {
163+
Some(v.as_str().parse::<u32>()?)
164+
}
165+
None => {
166+
match version_match.name("post_n2") {
167+
Some(v) => {
168+
Some(v.as_str().parse::<u32>()?)
169+
},
170+
_ => None,
171+
}
172+
}
173+
};
174+
175+
let post_head: Option<PostHead> = match version_match.name("post_l") {
176+
Some(v) => {
177+
match v.as_str() {
178+
"post" => Some(PostHead::Post),
179+
"rev" => Some(PostHead::Rev),
180+
"r" => Some(PostHead::Rev),
181+
// This branch Should be impossible (see regex-group post_l)
182+
_ => None,
183+
}
184+
}
185+
None => None
186+
};
187+
188+
Some(PostHeader {
189+
post_head,
190+
post_num,
191+
})
192+
},
149193
None => None,
150194
};
151195

@@ -162,6 +206,7 @@ impl PackageVersion {
162206
};
163207

164208
Ok(Self {
209+
original: version.to_string(),
165210
epoch,
166211
release,
167212
pre,

0 commit comments

Comments
 (0)
0