[][src]Struct version_compare::version::Version

pub struct Version<'a> { /* fields omitted */ }

Version struct, which is a representation for a parsed version string.

A version in string format can be parsed using methods like Version::from("1.2.3");. These methods return a Result holding the parsed version or an error on failure.

The original version string is stored in the struct, and can be accessed using the version.as_str() method. Note, that when the version wasn't parsed from a string representation, the returned value is generated.

The struct provides many methods for comparison and probing.

Implementations

impl<'a> Version<'a>[src]

pub fn from(version: &'a str) -> Option<Self>[src]

Create a Version instance from a version string.

The version string should be passed to the version parameter.

Examples

use version_compare::{CompOp, Version};

let ver = Version::from("1.2.3").unwrap();

assert_eq!(ver.compare(&Version::from("1.2.3").unwrap()), CompOp::Eq);

pub fn from_parts(version: &'a str, version_parts: Vec<VersionPart<'a>>) -> Self[src]

Create a Version instance from already existing parts

Examples

use version_compare::{CompOp, Version, VersionManifest};

pub fn from_manifest(
    version: &'a str,
    manifest: &'a VersionManifest
) -> Option<Self>
[src]

Create a Version instance from a version string with the given manifest.

The version string should be passed to the version parameter.

Examples

use version_compare::{CompOp, Version, VersionManifest};

let manifest = VersionManifest::new();
let ver = Version::from_manifest("1.2.3", &manifest).unwrap();

assert_eq!(ver.compare(&Version::from("1.2.3").unwrap()), CompOp::Eq);

pub fn manifest(&self) -> Option<&VersionManifest>[src]

Get the version manifest, if available.

Examples

use version_compare::Version;

let version = Version::from("1.2.3").unwrap();

if version.has_manifest() {
    println!(
        "Maximum version part depth is {} for this version",
        version.manifest().unwrap().max_depth_number()
    );
} else {
    println!("Version has no manifest");
}

pub fn has_manifest(&self) -> bool[src]

Check whether this version has a manifest.

Examples

use version_compare::Version;

let version = Version::from("1.2.3").unwrap();

if version.has_manifest() {
    println!("This version does have a manifest");
} else {
    println!("This version does not have a manifest");
}

pub fn set_manifest(&mut self, manifest: Option<&'a VersionManifest>)[src]

Set the version manifest.

Examples

use version_compare::{Version, VersionManifest};

let manifest = VersionManifest::new();
let mut version = Version::from("1.2.3").unwrap();

version.set_manifest(Some(&manifest));

pub fn as_str(&self) -> &str[src]

Get the original version string.

Examples

use version_compare::Version;

let ver = Version::from("1.2.3").unwrap();

assert_eq!(ver.as_str(), "1.2.3");

pub fn part(&self, index: usize) -> Result<&VersionPart<'a>, ()>[src]

Get a specific version part by it's index. An error is returned if the given index is out of bound.

Examples

use version_compare::{Version, VersionPart};

let ver = Version::from("1.2.3").unwrap();

assert_eq!(ver.part(0), Ok(&VersionPart::Number(1)));
assert_eq!(ver.part(1), Ok(&VersionPart::Number(2)));
assert_eq!(ver.part(2), Ok(&VersionPart::Number(3)));

pub fn parts(&self) -> &Vec<VersionPart<'a>>[src]

Get a vector of all version parts.

Examples

use version_compare::{Version, VersionPart};

let ver = Version::from("1.2.3").unwrap();

assert_eq!(ver.parts(), &vec![
    VersionPart::Number(1),
    VersionPart::Number(2),
    VersionPart::Number(3)
]);

pub fn part_count(&self) -> usize[src]

Get the number of parts in this version string.

Examples

use version_compare::Version;

let ver_a = Version::from("1.2.3").unwrap();
let ver_b = Version::from("1.2.3.4").unwrap();

assert_eq!(ver_a.part_count(), 3);
assert_eq!(ver_b.part_count(), 4);

pub fn compare(&self, other: &'a Version<'_>) -> CompOp[src]

Compare this version to the given other version.

This method returns one of the following comparison operators:

  • Lt
  • Eq
  • Gt

Other comparison operators can be used when comparing, but aren't returned by this method.

Examples:

use version_compare::{CompOp, Version};

assert_eq!(Version::from("1.2").unwrap().compare(&Version::from("1.3.2").unwrap()), CompOp::Lt);
assert_eq!(Version::from("1.9").unwrap().compare(&Version::from("1.9").unwrap()), CompOp::Eq);
assert_eq!(Version::from("0.3.0.0").unwrap().compare(&Version::from("0.3").unwrap()), CompOp::Eq);
assert_eq!(Version::from("2").unwrap().compare(&Version::from("1.7.3").unwrap()), CompOp::Gt);

pub fn compare_to(&self, other: &Version<'_>, operator: &CompOp) -> bool[src]

Compare this version to the given other version, and check whether the given comparison operator is valid.

All comparison operators can be used.

Examples:

use version_compare::{CompOp, Version};

assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.3.2").unwrap(), &CompOp::Lt));
assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.3.2").unwrap(), &CompOp::Le));
assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.2").unwrap(), &CompOp::Eq));
assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.2").unwrap(), &CompOp::Le));

Trait Implementations

impl<'a> Debug for Version<'a>[src]

impl<'a> Display for Version<'a>[src]

impl<'a> PartialEq<Version<'a>> for Version<'a>[src]

Implement the partial equality trait for the version struct, to easily allow version comparison.

impl<'a> PartialOrd<Version<'a>> for Version<'a>[src]

Implement the partial ordering trait for the version struct, to easily allow version comparison.

Auto Trait Implementations

impl<'a> RefUnwindSafe for Version<'a>

impl<'a> Send for Version<'a>

impl<'a> Sync for Version<'a>

impl<'a> Unpin for Version<'a>

impl<'a> UnwindSafe for Version<'a>

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