pub struct Version { /* private fields */ }Expand description
A version number such as 1.2.3 or 4!5.6.7-a8.post9.dev0.
Beware that the sorting implemented with Ord and Eq is not consistent with the operators
from PEP 440, i.e. compare two versions in rust with > gives a different result than a
VersionSpecifier with > as operator.
Parse with Version::from_str:
use std::str::FromStr;
use pep440_rs::Version;
let version = Version::from_str("1.19").unwrap();Implementations§
Source§impl Version
impl Version
Sourcepub fn new<I, R>(release_numbers: I) -> Version
pub fn new<I, R>(release_numbers: I) -> Version
Create a new version from an iterator of segments in the release part of a version.
§Panics
When the iterator yields no elements.
Sourcepub fn any_prerelease(&self) -> bool
pub fn any_prerelease(&self) -> bool
Whether this is an alpha/beta/rc or dev version
Sourcepub fn is_stable(&self) -> bool
pub fn is_stable(&self) -> bool
Whether this is a stable version (i.e., not an alpha/beta/rc or dev version)
Sourcepub fn is_local(&self) -> bool
pub fn is_local(&self) -> bool
Whether this is a local version (e.g. 1.2.3+localsuffixesareweird)
When true, it is guaranteed that the slice returned by
Version::local is non-empty.
Sourcepub fn pre(&self) -> Option<Prerelease>
pub fn pre(&self) -> Option<Prerelease>
Returns the pre-release part of this version, if it exists.
Sourcepub fn local(&self) -> &[LocalSegment]
pub fn local(&self) -> &[LocalSegment]
Returns the local segments in this version, if any exist.
Sourcepub fn min(&self) -> Option<u64>
pub fn min(&self) -> Option<u64>
Returns the min-release part of this version, if it exists.
The “min” component is internal-only, and does not exist in PEP 440.
The version 1.0min0 is smaller than all other 1.0 versions,
like 1.0a1, 1.0dev0, etc.
Sourcepub fn max(&self) -> Option<u64>
pub fn max(&self) -> Option<u64>
Returns the max-release part of this version, if it exists.
The “max” component is internal-only, and does not exist in PEP 440.
The version 1.0max0 is larger than all other 1.0 versions,
like 1.0.post1, 1.0+local, etc.
Sourcepub fn with_release<I, R>(self, release_numbers: I) -> Version
pub fn with_release<I, R>(self, release_numbers: I) -> Version
Set the release numbers and return the updated version.
Usually one can just use Version::new to create a new version with
the updated release numbers, but this is useful when one wants to
preserve the other components of a version number while only changing
the release numbers.
§Panics
When the iterator yields no elements.
Sourcepub fn with_epoch(self, value: u64) -> Version
pub fn with_epoch(self, value: u64) -> Version
Set the epoch and return the updated version.
Sourcepub fn with_pre(self, value: Option<Prerelease>) -> Version
pub fn with_pre(self, value: Option<Prerelease>) -> Version
Set the pre-release component and return the updated version.
Sourcepub fn with_post(self, value: Option<u64>) -> Version
pub fn with_post(self, value: Option<u64>) -> Version
Set the post-release component and return the updated version.
Sourcepub fn with_dev(self, value: Option<u64>) -> Version
pub fn with_dev(self, value: Option<u64>) -> Version
Set the dev-release component and return the updated version.
Sourcepub fn with_local(self, value: Vec<LocalSegment>) -> Version
pub fn with_local(self, value: Vec<LocalSegment>) -> Version
Set the local segments and return the updated version.
Sourcepub fn without_local(self) -> Version
pub fn without_local(self) -> Version
For PEP 440 specifier matching: “Except where specifically noted below, local version identifiers MUST NOT be permitted in version specifiers, and local version labels MUST be ignored entirely when checking if candidate versions match a given version specifier.”
Sourcepub fn only_release(&self) -> Version
pub fn only_release(&self) -> Version
Return the version with any segments apart from the release removed.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Version
impl<'de> Deserialize<'de> for Version
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Version, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Version, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for Version
Source§impl Ord for Version
impl Ord for Version
Source§fn cmp(&self, other: &Version) -> Ordering
fn cmp(&self, other: &Version) -> Ordering
1.0.dev456 < 1.0a1 < 1.0a2.dev456 < 1.0a12.dev456 < 1.0a12 < 1.0b1.dev456 < 1.0b2 < 1.0b2.post345.dev456 < 1.0b2.post345 < 1.0b2-346 < 1.0c1.dev456 < 1.0c1 < 1.0rc2 < 1.0c3 < 1.0 < 1.0.post456.dev34 < 1.0.post456
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Version
impl PartialOrd for Version
Source§impl Serialize for Version
impl Serialize for Version
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnsafeUnpin for Version
impl UnwindSafe for Version
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more