Struct pep440_rs::Version

source ·
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

source

pub fn new<I, R>(release_numbers: I) -> Version
where I: IntoIterator<Item = R>, R: Borrow<u64>,

Create a new version from an iterator of segments in the release part of a version.

§Panics

When the iterator yields no elements.

source

pub fn any_prerelease(&self) -> bool

Whether this is an alpha/beta/rc or dev version

source

pub fn is_pre(&self) -> bool

Whether this is an alpha/beta/rc version

source

pub fn is_dev(&self) -> bool

Whether this is a dev version

source

pub fn is_post(&self) -> bool

Whether this is a post version

source

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.

source

pub fn epoch(&self) -> u64

Returns the epoch of this version.

source

pub fn release(&self) -> &[u64]

Returns the release number part of the version.

source

pub fn pre(&self) -> Option<PreRelease>

Returns the pre-release part of this version, if it exists.

source

pub fn post(&self) -> Option<u64>

Returns the post-release part of this version, if it exists.

source

pub fn dev(&self) -> Option<u64>

Returns the dev-release part of this version, if it exists.

source

pub fn local(&self) -> &[LocalSegment]

Returns the local segments in this version, if any exist.

source

pub fn with_release<I, R>(self, release_numbers: I) -> Version
where I: IntoIterator<Item = R>, R: Borrow<u64>,

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.

source

pub fn with_epoch(self, value: u64) -> Version

Set the epoch and return the updated version.

source

pub fn with_pre(self, value: Option<PreRelease>) -> Version

Set the pre-release component and return the updated version.

source

pub fn with_post(self, value: Option<u64>) -> Version

Set the post-release component and return the updated version.

source

pub fn with_dev(self, value: Option<u64>) -> Version

Set the dev-release component and return the updated version.

source

pub fn with_local(self, value: Vec<LocalSegment>) -> Version

Set the local segments and return the updated version.

source

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 Clone for Version

source§

fn clone(&self) -> Version

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Version

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Version

Shows normalized version

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Version

source§

fn from_str(version: &str) -> Result<Self, Self::Err>

Parses a version such as 1.19, 1.0a1,1.0+abc.5 or 1!2012.2

Note that this doesn’t allow wildcard versions.

§

type Err = VersionParseError

The associated error which can be returned from parsing.
source§

impl Hash for Version

source§

fn hash<H: Hasher>(&self, state: &mut H)

Custom implementation to ignoring trailing zero because PartialEq zero pads

1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for Version

source§

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) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Version

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Version

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

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

fn le(&self, other: &Rhs) -> bool

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

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl Eq for Version

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.