Skip to main content

Version

Struct 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_stable(&self) -> bool

Whether this is a stable version (i.e., not 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 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.

Source

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.

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.”

Source

pub fn only_release(&self) -> Version

Return the version with any segments apart from the release removed.

Source

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

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

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.

Source

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

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

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.

Trait Implementations§

Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<(), Error>

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

impl<'de> Deserialize<'de> for Version

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Version, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Version

Shows normalized version

Source§

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

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

impl Eq for Version

Source§

impl FromStr for Version

Source§

fn from_str(version: &str) -> Result<Version, <Version as FromStr>::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.

Source§

type Err = VersionParseError

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

impl Hash for Version

Source§

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

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Version

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Version

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Version

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

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§

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> Ungil for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more