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., the1.2.3
ofv1.2.3rc0.post0.dev1+123
) is stored as a vector ofu32
integers. This allows for easier ordering comparison later. -
The
pre
component, if it exists, is stored as aPreRelease
, which allows for all of the valid pre-release identifiers that PEP440 specifies. These area
(alpha),b
(beta), andrc
(release candidate). -
The
local
component is stored as a vector ofLocalVersion
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: u32
release: 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
This implementation is returns the normalized version of the version.
It is equivalent to calling normalize()
on the version.
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
Auto Trait Implementations
impl RefUnwindSafe for Version
impl UnwindSafe for Version
Blanket Implementations
Mutably borrows from an owned value. Read more