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_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 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.”
Trait Implementations§
source§impl Ord for Version
impl Ord for Version
source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> 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 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for Version
impl PartialEq for Version
source§impl PartialOrd for Version
impl PartialOrd for Version
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more