Crate semver_rs[][src]

Expand description

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).parse()?;
let ver = Version::new("1.2.4-pre1").with_options(opts).parse()?;

assert!(range.test(&ver));
Serialisation with Serde
use semver_rs::{Range, Options};

let opts = Options::builder().loose(true).include_prerelease(true).build();
let range = Range::new(">=1.2.3").with_options(opts).parse()?;
let _ = serde_json::to_string(&opts)?;

Structs

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

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

Allows building an Options instance.

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:

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

Enums

An error returned during parsing of Versions or Ranges.

Traits

Functions

Cleanups a semver string making it semver complaint.

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

Compares the ordering of Version a vs Version b.

Parses a string into a Version.

Checks whether Version is in a Range.