[][src]Crate semver_rs

Semantic version parsing and comparison (semver). The implementation of this crate is based on the node-semver npm package. The tests are taken directly from node-semver's repo. This should make this crate equally good at parsing semver expressions as the node package manager.

Examples

Comparing two versions:

use semver_rs::Version;

// by constructing version instances manually
let ver1 = Version::new("2.0.0").parse()?;
let ver2 = Version::new("1.2.3").parse()?;

assert!(ver1 > ver2);

// by using the exported helper function
use semver_rs::compare;
use std::cmp::Ordering;

assert!(compare("2.0.0", "1.2.3", None)? == Ordering::Greater);

Checking whether a version is in a range

use semver_rs::{Range, Version};

// by constructing version instances manually
let range = Range::new(">=1.2.3").parse()?;
let ver = Version::new("1.2.4").parse()?;

assert!(range.test(&ver));

// by using the exported helper function
use semver_rs::satisfies;

assert!(satisfies("1.2.4", ">=1.2.4", None)?);

Parsing with specific options

use semver_rs::{Version, Range, Options};

let opts = Options::builder().loose(true).include_prerelease(true).build();
let range = Range::new(">=1.2.3").with_options(opts.clone()).parse()?;
let ver = Version::new("1.2.4-pre1").with_options(opts.clone()).parse()?;

assert!(range.test(&ver));

Structs

Builder

A Builder that helps create instances of Version and Range by also optionally supplying Options.

Error

An error returned during parsing of Versions or Ranges. Use the kind method to get the type of error.

Options

Allows to configure the parsing of semver strings, same as the node-semver package. All options are false by default.

OptionsBuilder

Allows building an Options instance.

Range

A version range is a set of comparators which specify versions that satisfy the range. A comparator is composed of an operator and a version. The set of primitive operators is:

Version

A version is described by the v2.0.0 specification found at semver.

Enums

ErrorKind
Operator

Traits

Parseable

Functions

clean

Cleanups a semver string making it semver complaint.

cmp

Compares whether Version a matches the semver operator against Version b.

compare

Compares the ordering of Version a vs Version b.

parse

Parses a string into a Version.

satisfies

Checks whether Version is in a Range.