[][src]Struct versions::Version

pub struct Version {
    pub epoch: Option<u32>,
    pub chunks: Chunks,
    pub meta: Option<Chunks>,
    pub release: Option<Chunks>,
}

A version number with decent structure and comparison logic.

This is a descriptive scheme, meaning that it encapsulates the most common, unconscious patterns that developers use when assigning version numbers to their software. If not SemVer, most version numbers found in the wild will parse as a Version. These generally conform to the x.x.x-x pattern, and may optionally have an epoch.

Epochs

Epochs are prefixes marked by a colon, like in 1:2.3.4. When comparing two Version values, epochs take precedent. So 2:1.0.0 > 1:9.9.9. If one of the given Versions has no epoch, its epoch is assumed to be 0.

Examples

use versions::{SemVer, Version};

// None of these are SemVer, but can still be parsed and compared.
let vers = vec!["0.25-2", "8.u51-1", "20150826-1", "1:2.3.4"];

for v in vers {
    assert!(SemVer::new(v).is_none());
    assert!(Version::new(v).is_some());
}

Fields

epoch: Option<u32>chunks: Chunksmeta: Option<Chunks>release: Option<Chunks>

Implementations

impl Version[src]

pub fn new(s: &str) -> Option<Version>[src]

Parse a Version from some input.

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

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

use versions::Version;

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

pub fn nth_lenient(&self, n: usize) -> Option<u32>[src]

Like nth, but pulls a number even if it was followed by letters.

pub fn to_mess(&self) -> Mess[src]

A lossless conversion from Version to Mess.

use versions::Version;

let orig = "1:1.2.3-r1";
let mess = Version::new(orig).unwrap().to_mess();

assert_eq!(orig, format!("{}", mess));

Trait Implementations

impl Clone for Version[src]

impl Debug for Version[src]

impl Display for Version[src]

impl Eq for Version[src]

impl Hash for Version[src]

impl Ord for Version[src]

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

If two epochs are equal, we need to compare their actual version numbers. Otherwise, the comparison of the epochs is the only thing that matters.

impl PartialEq<Version> for Version[src]

impl PartialOrd<Version> for Version[src]

impl StructuralEq for Version[src]

impl StructuralPartialEq for Version[src]

Auto Trait Implementations

impl RefUnwindSafe for Version

impl Send for Version

impl Sync for Version

impl Unpin for Version

impl UnwindSafe for Version

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.