Skip to content
Closed
Show file tree
Hide file tree
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
Added docs
- Added doc strings
- Added usage example
  • Loading branch information
Allstreamer committed Aug 10, 2022
commit c944ce15480ea66184e8eeb3e5a8d98039e62037
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::{AppSettings, Parser};
use package_version::PackageVersion;

#[macro_use]
extern crate derivative;
Expand Down Expand Up @@ -48,7 +49,10 @@ enum Opt {
Help {},
}

fn download_package(_package_name: String, _package_index: &str) {}
fn download_package(_package_name: String, _package_index: &str) {
// Version usage example
let _ = PackageVersion::new("v1.0");
}

fn main() {
let opt = Opt::parse();
Expand Down
45 changes: 27 additions & 18 deletions src/package_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static VALIDATION_REGEX: &'static str = pomsky!(
)?
);

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

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

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

/// This struct is sorted so that PartialOrd
/// corretly interpets priority
///
///
/// Lower == More important
#[derive(Derivative, Debug, Serialize, Deserialize, Eq)]
#[derivative(PartialOrd)]
///
/// # Example Usage
/// ```
/// let _ = PackageVersion::new("v1.0");
/// ```
#[derive(Derivative, Debug, Serialize, Deserialize)]
#[derivative(PartialOrd, PartialEq)]
pub struct PackageVersion {
#[derivative(PartialEq="ignore")]
#[derivative(PartialOrd = "ignore", PartialEq = "ignore")]
pub original: String,

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

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

/// # Pep-440 Developmental release identifier
/// # Pep-440 Post-Release identifier
pub post: Option<PostHeader>,

/// # Pep-440 Pre-Release identifier
Expand Down Expand Up @@ -274,17 +291,6 @@ impl fmt::Display for PackageVersion {
}
}

impl PartialEq for PackageVersion {
fn eq(&self, other: &Self) -> bool {
self.epoch == other.epoch
&& self.release == other.release
&& self.pre == other.pre
&& self.post == other.post
&& self.dev == other.dev
&& self.local == other.local
}
}

#[cfg(test)]
mod tests {
use std::fmt::Debug;
Expand Down Expand Up @@ -334,7 +340,10 @@ mod tests {
)?;
check_a_greater(
ReleaseHeader { major: 2, minor: 1 },
ReleaseHeader { major: 1, minor: 52 },
ReleaseHeader {
major: 1,
minor: 52,
},
)?;
Ok(())
}
Expand Down