8000 Added docs · Allstreamer/rust-pip@c944ce1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c944ce1

Browse files
committed
Added docs
- Added doc strings - Added usage example
1 parent f3595cd commit c944ce1

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::{AppSettings, Parser};
2+
use package_version::PackageVersion;
23

34
#[macro_use]
45
extern crate derivative;
@@ -48,7 +49,10 @@ enum Opt {
4849
Help {},
4950
}
5051

51-
fn download_package(_package_name: String, _package_index: &str) {}
52+
fn download_package(_package_name: String, _package_index: &str) {
53+
// Version usage example
54+
let _ = PackageVersion::new("v1.0");
55+
}
5256

5357
fn main() {
5458
let opt = Opt::parse();

src/package_version.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static VALIDATION_REGEX: &'static str = pomsky!(
5252
)?
5353
);
5454

55+
/// # Pep-440 Developmental release identifier
5556
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd)]
5657
pub struct DevHead {
5758
dev_num: Option<u32>,
@@ -69,6 +70,7 @@ impl PartialOrd for PostHead {
6970
}
7071
}
7172

73+
/// # Pep-440 Post-Release identifier
7274
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
7375
pub struct PostHeader {
7476
pub post_head: Option<PostHead>,
@@ -95,6 +97,7 @@ impl PartialOrd for PostHeader {
9597
}
9698
}
9799

100+
/// # Pep-440 Pre-Release identifier
98101
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, PartialOrd)]
99102
pub enum PreHeader {
100103
Beta(Option<u32>),
@@ -118,24 +121,38 @@ pub struct ReleaseHeader {
118121

119122
/// This struct is sorted so that PartialOrd
120123
/// corretly interpets priority
121-
///
124+
///
122125
/// Lower == More important
123-
#[derive(Derivative, Debug, Serialize, Deserialize, Eq)]
124-
#[derivative(PartialOrd)]
126+
///
127+
/// # Example Usage
128+
/// ```
129+
/// let _ = PackageVersion::new("v1.0");
130+
/// ```
131+
#[derive(Derivative, Debug, Serialize, Deserialize)]
132+
#[derivative(PartialOrd, PartialEq)]
125133
pub struct PackageVersion {
126-
#[derivative(PartialEq="ignore")]
134+
#[derivative(PartialOrd = "ignore", PartialEq = "ignore")]
127135
pub original: String,
128136

129137
/// # Pep-440 Local version identifier
130138
/// Local version sorting will have to be it's own issue
131139
/// since there are no limits to what a local version can be
132-
#[derivative(PartialEq="ignore")]
140+
///
141+
/// For those who can read regex here it is for the local version:
142+
/// `[a-z0-9]+(?:(?:[\-_.][a-z0-9]+)+)?`
143+
///
144+
/// Here in Rulex:
145+
/// ```
146+
/// ['a'-'z' '0'-'9']+
147+
/// ((["-" "_" "."] ['a'-'z' '0'-'9']+)+)?
148+
/// ```
149+
#[derivative(PartialOrd = "ignore", PartialEq = "ignore")]
133150
pub local: Option<String>,
134151

135152
/// # Pep-440 Developmental release identifier
136153
pub dev: Option<DevHead>,
137154

138-
/// # Pep-440 Developmental release identifier
155+
/// # Pep-440 Post-Release identifier
139156
pub post: Option<PostHeader>,
140157

141158
/// # Pep-440 Pre-Release identifier
@@ -274,17 +291,6 @@ impl fmt::Display for PackageVersion {
274291
}
275292
}
276293

277-
impl PartialEq for PackageVersion {
278-
fn eq(&self, other: &Self) -> bool {
279-
self.epoch == other.epoch
280-
&& self.release == other.release
281-
&& self.pre == other.pre
282-
&& self.post == other.post
283-
&& self.dev == other.dev
284-
&& self.local == other.local
285-
}
286-
}
287-
288294
#[cfg(test)]
289295
mod tests {
290296
use std::fmt::Debug;
@@ -334,7 +340,10 @@ mod tests {
334340
)?;
335341
check_a_greater(
336342
ReleaseHeader { major: 2, minor: 1 },
337-
ReleaseHeader { major: 1, minor: 52 },
343+
ReleaseHeader {
344+
major: 1,
345+
minor: 52,
346+
},
338347
)?;
339348
Ok(())
340349
}

0 commit comments

Comments
 (0)
0