Enum versions::Versioning

source ·
pub enum Versioning {
    Ideal(SemVer),
    General(Version),
    Complex(Mess),
}
Expand description

A top-level Versioning type which acts as a wrapper for the more specific types.

§Examples

use versions::Versioning;

let a = Versioning::new("1.2.3-1").unwrap();   // SemVer.
let b = Versioning::new("1.2.3r1").unwrap();   // Not SemVer but good enough.
let c = Versioning::new("000.007-1").unwrap(); // Garbage.

assert!(a.is_ideal());
assert!(b.is_general());
assert!(c.is_complex());

Variants§

§

Ideal(SemVer)

Follows good parsing and comparison rules.

§

General(Version)

A little more permissive than SemVer.

§

Complex(Mess)

Hope that you need not venture here.

Implementations§

source§

impl Versioning

source

pub fn new(s: &str) -> Option<Versioning>

Create a Versioning by attempting to parse the input first as SemVer, then as a Version, and finally as a Mess.

source

pub fn parse(i: &str) -> IResult<&str, Versioning>

The raw nom parser for Versioning. Feel free to use this in combination with other general nom parsers.

source

pub fn is_ideal(&self) -> bool

A short-hand for detecting an inner SemVer.

source

pub fn is_general(&self) -> bool

A short-hand for detecting an inner Version.

source

pub fn is_complex(&self) -> bool

A short-hand for detecting an inner Mess.

source

pub fn nth(&self, n: usize) -> Option<u32>

Try to extract a position from the Versioning as a nice integer, as if it were a SemVer.

use versions::Versioning;

let semver = Versioning::new("1.2.3-r1+git123").unwrap();
assert!(semver.is_ideal());
assert_eq!(Some(1), semver.nth(0));
assert_eq!(Some(2), semver.nth(1));
assert_eq!(Some(3), semver.nth(2));

let version = Versioning::new("1:2.a.4.5.6.7-r1").unwrap();
assert!(version.is_general());
assert_eq!(Some(2), version.nth(0));
assert_eq!(None, version.nth(1));
assert_eq!(Some(4), version.nth(2));

let mess = Versioning::new("1.6a.0+2014+m872b87e73dfb-1").unwrap();
assert!(mess.is_complex());
assert_eq!(Some(1), mess.nth(0));
assert_eq!(None, mess.nth(1));
assert_eq!(Some(0), mess.nth(2));

Trait Implementations§

source§

impl Clone for Versioning

source§

fn clone(&self) -> Versioning

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 Versioning

source§

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

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

impl Default for Versioning

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Versioning

source§

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

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

impl FromStr for Versioning

§

type Err = Error

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

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

Parses a string s to return a value of this type. Read more
source§

impl Hash for Versioning

source§

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

Feeds this value into the given Hasher. Read more
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 Versioning

source§

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

This method returns an Ordering between self and other. Read more
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 Versioning

source§

fn eq(&self, other: &Versioning) -> 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 Versioning

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 TryFrom<&str> for Versioning

source§

fn try_from(value: &str) -> Result<Self, Self::Error>

use versions::Versioning;

let orig = "1.2.3";
let prsd: Versioning = orig.try_into().unwrap();
assert_eq!(orig, prsd.to_string());
§

type Error = Error

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

impl Eq for Versioning

source§

impl StructuralPartialEq for Versioning

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.