Struct pep440::Version[][src]

pub struct Version {
    pub epoch: u32,
    pub release: Vec<u32>,
    pub pre: Option<PreRelease>,
    pub post: Option<u32>,
    pub dev: Option<u32>,
    pub local: Vec<LocalVersion>,
}
Expand description

Represents a version parsed as a PEP440-compliant version string.

Several things to note:

  • All integer values are stored as u32. This is somewhat arbitrary, but based on the fact that PEP440 defines no specification for these numbers, beyond the fact that they are positive (thus our use of unsigned).

  • The release component (i.e., the 1.2.3 of v1.2.3rc0.post0.dev1+123) is stored as a vector of u32 integers. This allows for easier ordering comparison later.

  • The pre component, if it exists, is stored as a PreRelease, which allows for all of the valid pre-release identifiers that PEP440 specifies. These are a (alpha), b (beta), and rc (release candidate).

  • The local component is stored as a vector of LocalVersion components. This is because the “local” version is allowed to contain both numeric and string pieces, and we need to be able to account for both.

Fields

epoch: u32release: Vec<u32>pre: Option<PreRelease>post: Option<u32>dev: Option<u32>local: Vec<LocalVersion>

Implementations

Returns true if the given version is in its canonical form, false if not.

Attempt to parse the given input string as a PEP440-compliant version string. By default, we base this on the same regex that is given at the bottom of the PEP440 specification. Release labels (alpha, a, rc, dev, post, etc.) are case-insensitive.

Returns the normalized form of the epoch for the version. This will either be a number followed by a !, or the empty string.

let ver = Version::parse("1!2.3.4rc0").unwrap();
assert_eq!(ver.epoch_str(), "1!".to_string());
let ver = Version::parse("2.3.4rc0").unwrap();
assert_eq!(ver.epoch_str(), "".to_string());

Returns the normalized form of the release for the version. This will be the release component of the input, but with leading zeros removed from each segment.

let ver = Version::parse("2.3.4post3.dev6").unwrap();
assert_eq!(ver.release_str(), "2.3.4".to_string());
let ver = Version::parse("v002.03.000004post3.dev6").unwrap();
assert_eq!(ver.release_str(), "2.3.4".to_string());

Returns the normalized form of the pre-release field for the version. If no pre-release is given, the empty string will be returned.

Non-canonical strings will be turned into canonical ones. For example, alpha3 will be turned into a3, and preview9 will be turned into rc9.

let ver = Version::parse("2.3.4c4.post3.dev6").unwrap();
assert_eq!(ver.pre_str(), "rc4".to_string());
let ver = Version::parse("2.3.4.alpha8").unwrap();
assert_eq!(ver.pre_str(), "a8".to_string());
let ver = Version::parse("2.3.4").unwrap();
assert_eq!(ver.pre_str(), "".to_string());

Returns the normalized form of the post-release field for the version. If no post-release is given, the empty string will be returned.

If a string is returned, it includes a leading . which is required in normalized renditions of a version.

let ver = Version::parse("2.3.4c4.post3.dev6").unwrap();
assert_eq!(ver.post_str(), ".post3".to_string());
let ver = Version::parse("2.3.4-3.dev6").unwrap();
assert_eq!(ver.post_str(), ".post3".to_string());
let ver = Version::parse("2.3.4.alpha8").unwrap();
assert_eq!(ver.post_str(), "".to_string());

Returns the normalized form of the dev-release field for the version. If no dev-release is given, the empty string will be returned.

If a string is returned, it includes a leading . which is required in normalized renditions of a version.

let ver = Version::parse("2.3.4c4.post3.dev6").unwrap();
assert_eq!(ver.dev_str(), ".dev6".to_string());
let ver = Version::parse("2.3.4.alpha8").unwrap();
assert_eq!(ver.dev_str(), "".to_string());

Returns the normalized form of the local field for the version. If no local component is given, the empty string will be returned.

If a string is returned, it includes a leading + which is required in normalized renditions of a version.

let ver = Version::parse("2.3.4c4.post3.dev6+123.foo_deb-3").unwrap();
assert_eq!(ver.local_str(), "+123.foo.deb.3".to_string());
let ver = Version::parse("2.3.4.alpha8").unwrap();
assert_eq!(ver.local_str(), "".to_string());

Returns public portion of the version in normalized form.

This is equivalent to all components except the “local” portion of the version.

let ver = Version::parse("2.3.4c4.post3.dev6+123.foo_deb-3").unwrap();
assert_eq!(ver.public_str(), "2.3.4rc4.post3.dev6".to_string());

Returns the normalized form of the version by combining all of the segments in their normalized form as returned by the *_str() methods defined above.

This method is also used to implement Display for Version and the result will be identical.

let ver = Version::parse("v2.3.4c4.post3.dev6+1.f-3").unwrap();
assert_eq!(ver.normalize(), "2.3.4rc4.post3.dev6+1.f.3".to_string());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This implementation is returns the normalized version of the version. It is equivalent to calling normalize() on the version.

let ver = Version::parse("v2.3.4c4.post3.dev6+1.f-3").unwrap();
assert_eq!(format!("{}", ver), ver.normalize());

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

let ver1 = Version::parse("v2.3.4c4.post3.dev6+1.f-3").unwrap();
let ver2 = Version::parse("v2.3.4pre4.post3.dev6+1.f-3").unwrap();
assert_eq!(ver1.partial_cmp(&ver2), Some(Ordering::Equal))

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.