Struct pep440::Version [−][src]
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
impl Version
[src]
pub fn is_canonical(input: &str) -> bool
[src]
Returns true
if the given version is in its canonical form, false
if not.
pub fn parse(input: &str) -> Option<Version>
[src]
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.
pub fn epoch_str(&self) -> String
[src]
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());
pub fn release_str(&self) -> String
[src]
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());
pub fn pre_str(&self) -> String
[src]
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());
pub fn post_str(&self) -> String
[src]
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());
pub fn dev_str(&self) -> String
[src]
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());
pub fn local_str(&self) -> String
[src]
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());
pub fn public_str(&self) -> String
[src]
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());
pub fn normalize(&self) -> String
[src]
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
impl Clone for Version
[src]
impl Debug for Version
[src]
impl Display for Version
[src]
This implementation is returns the normalized version of the version.
It is equivalent to calling normalize()
on the version.
fn fmt(&self, f: &mut Formatter<'_>) -> Result
[src]
let ver = Version::parse("v2.3.4c4.post3.dev6+1.f-3").unwrap(); assert_eq!(format!("{}", ver), ver.normalize());
impl Eq for Version
[src]
impl Ord for Version
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Version> for Version
[src]
impl PartialOrd<Version> for Version
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
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))
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for Version
[src]
impl StructuralPartialEq for Version
[src]
Auto Trait Implementations
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnwindSafe for Version
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,