ValidUpstreamVersion

Struct ValidUpstreamVersion 

Source
pub struct ValidUpstreamVersion<'a>(/* private fields */);
Expand description

Upstream version which has been validated.

Implementations§

Source§

impl<'a> ValidUpstreamVersion<'a>

Source

pub fn as_str(&self) -> &'a str

Get an immutable reference to the raw string underneath.

Source

pub fn components(&self) -> UpstreamVersionComponentIter<'a>

Iterate over all components of the version.

Components are separated by dots (.), underscores (_), plus signs (+), or at signs (@). All separators are treated the same way because they are treated the same by vercmp.

Trait Implementations§

Source§

impl<'a> AsRef<&'a str> for ValidUpstreamVersion<'a>

Source§

fn as_ref(&self) -> &&'a str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Clone for ValidUpstreamVersion<'a>

Source§

fn clone(&self) -> ValidUpstreamVersion<'a>

Returns a duplicate 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<'a> Debug for ValidUpstreamVersion<'a>

Source§

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

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

impl<'a> Display for ValidUpstreamVersion<'a>

Source§

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

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

impl<'a> From<ValidUpstreamVersion<'a>> for UpstreamVersion<'a>

Source§

fn from(value: ValidUpstreamVersion<'a>) -> Self

Converts to this type from the input type.
Source§

impl Hash for ValidUpstreamVersion<'_>

Source§

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

This custom hash algorithm was implemented in such a way to be consistent with ValidUpstreamVersion::cmp and ValidUpstreamVersion::eq.

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 ValidUpstreamVersion<'_>

Source§

fn cmp(&self, other: &Self) -> Ordering

Comparing two validated upstream versions.

This comparison aims to emulate vercmp’s algorithm on validated upstream versions.

let validate = |raw| UpstreamVersion(raw).validate().unwrap();

// Two versions are considered equal if their internal strings are equal
assert!(validate("1.2.3") == validate("1.2.3"));
assert!(validate("1.2_3") == validate("1.2_3"));
assert!(validate("1_2_3") == validate("1_2_3"));

// Each component pair of two versions are compared until an unequal pair is found
assert!(validate("1.2.0") < validate("1.2.3"));
assert!(validate("1.3.2") > validate("1.2.3"));
assert!(validate("1.2.3.0.5.6") < validate("1.2.3.4.5.6"));
assert!(validate("1.2.3.4.5") > validate("1.2.3.2.1"));
assert!(validate("2.1.4") > validate("2.1.0.5"));
assert!(validate("1.1.0") < validate("1.2"));

// If one version is the leading part of another, the latter is considered greater
assert!(validate("1.1.0") > validate("1.1"));
assert!(validate("1.1.0") < validate("1.1.0.0"));

// The difference between dots, underscores, plus signs, and at signs are ignored
assert!(validate("1.2.3") == validate("1.2_3"));
assert!(validate("1.2.3") == validate("1_2_3"));
assert!(validate("1.2.0") < validate("1.2_3"));
assert!(validate("1_1.0") > validate("1.1"));
assert!(validate("1+2.3") == validate("1@2_3"));
assert!(validate("1@2@3") == validate("1+2+3"));
assert!(validate("1@2.0") < validate("1.2_3"));
assert!(validate("1_1.0") > validate("1+1"));

// Leading zeros are ignored
assert!(validate("01.02.3") == validate("1.2.03"));
assert!(validate("1.02.0") < validate("1.2.3"));
assert!(validate("1.01.0") > validate("1.1"));
assert!(validate("1.1.0") > validate("1.001"));

NOTE: For licensing reason, this trait method was implemented from scratch by testing case-by-case without looking at the source code of vercmp so there might be edge-cases and subtle differences. Contributors are welcomed to propose PRs to fix these edge-cases as long as they don’t look at the source code of vercmp.

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,

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

impl PartialEq for ValidUpstreamVersion<'_>

Source§

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

Return true if ValidUpstreamVersion::cmp returns Ordering::Equal. Otherwise, return false.

NOTE: Two versions being equal doesn’t necessarily means that their internal strings are equal. This is because dots (.), underscores (_), plus signs (+), and at signs (@) were ignored during parsing.

1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ValidUpstreamVersion<'_>

Source§

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

Return a Some(ordering) with ordering being the result of ValidUpstreamVersion::cmp.

1.0.0 · 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 · 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 · 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 · 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<'a> TryFrom<UpstreamVersion<'a>> for ValidUpstreamVersion<'a>

Source§

type Error = ValidateUpstreamVersionError<'a>

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

fn try_from(value: UpstreamVersion<'a>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> Copy for ValidUpstreamVersion<'a>

Source§

impl Eq for ValidUpstreamVersion<'_>

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<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, 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<X> Pipe for X

Source§

fn pipe<Return, Function>(self, f: Function) -> Return
where Self: Sized, Function: FnOnce(Self) -> Return,

Apply f to self. Read more
Source§

fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Return
where Function: FnOnce(&'a Self) -> Return,

Apply f to &self. Read more
Source§

fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Return
where Function: FnOnce(&'a mut Self) -> Return,

Apply f to &mut self. Read more
Source§

fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
where Self: AsRef<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a Param) -> Return,

Apply f to &self where f takes a single parameter of type Param and Self implements trait AsRef<Param>. Read more
Source§

fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return
where Self: AsMut<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a mut Param) -> Return,

Apply f to &mut self where f takes a single parameter of type Param and Self implements trait AsMut<Param>. Read more
Source§

fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
where Self: Deref<Target = Param>, Param: 'a + ?Sized, Function: FnOnce(&'a Param) -> Return,

Apply f to &self where f takes a single parameter of type Param and Self implements trait Deref<Target = Param>. Read more
Source§

fn pipe_deref_mut<'a, Param, Return, Function>( &'a mut self, f: Function, ) -> Return
where Self: DerefMut<Target = Param>, Param: 'a + ?Sized, Function: FnOnce(&'a mut Param) -> Return,

Apply f to &mut self where f takes a single parameter of type Param and Self implements trait DerefMut<Target = Param>. Read more
Source§

fn pipe_borrow<'a, Param, Return, Function>(&'a self, f: Function) -> Return
where Self: Borrow<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a Param) -> Return,

Apply f to &self where f takes a single parameter of type Param and Self implements trait Borrow<Param>. Read more
Source§

fn pipe_borrow_mut<'a, Param, Return, Function>( &'a mut self, f: Function, ) -> Return
where Self: BorrowMut<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a mut Param) -> Return,

Apply f to &mut self where f takes a single parameter of type Param and Self implements trait BorrowMut<Param>. 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 = 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>,

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.