Giter Site home page Giter Site logo

semver's Introduction

semver

Semantic version parsing and comparison.

Build Status

Documentation

Semantic versioning (see https://semver.org/) is a set of rules for assigning version numbers.

SemVer and the Rust ecosystem

Rust itself follows the SemVer specification, as does its standard libraries. The two are not tied together.

Cargo, Rust's package manager, uses SemVer to determine which versions of packages you need installed.

Installation

To use semver, add this to your [dependencies] section:

semver = "0.11.0"

And this to your crate root:

extern crate semver;

Versions

At its simplest, the semver crate allows you to construct Version objects using the parse method:

use semver::Version;

assert!(Version::parse("1.2.3") == Ok(Version {
   major: 1,
   minor: 2,
   patch: 3,
   pre: vec!(),
   build: vec!(),
}));

If you have multiple Versions, you can use the usual comparison operators to compare them:

use semver::Version;

assert!(Version::parse("1.2.3-alpha")  != Version::parse("1.2.3-beta"));
assert!(Version::parse("1.2.3-alpha2") >  Version::parse("1.2.0"));

Requirements

The semver crate also provides the ability to compare requirements, which are more complex comparisons.

For example, creating a requirement that only matches versions greater than or equal to 1.0.0:

use semver::Version;
use semver::VersionReq;

let r = VersionReq::parse(">= 1.0.0").unwrap();
let v = Version::parse("1.0.0").unwrap();

assert!(r.to_string() == ">= 1.0.0".to_string());
assert!(r.matches(&v))

It also allows parsing of ~x.y.z and ^x.y.z requirements as defined at https://www.npmjs.com/package/semver

Tilde requirements specify a minimal version with some updates:

~1.2.3 := >=1.2.3 <1.3.0
~1.2   := >=1.2.0 <1.3.0
~1     := >=1.0.0 <2.0.0

Caret requirements allow SemVer compatible updates to a specified version, 0.x and 0.x+1 are not considered compatible, but 1.x and 1.x+1 are.

0.0.x is not considered compatible with any other version. Missing minor and patch versions are desugared to 0 but allow flexibility for that value.

^1.2.3 := >=1.2.3 <2.0.0
^0.2.3 := >=0.2.3 <0.3.0
^0.0.3 := >=0.0.3 <0.0.4
^0.0   := >=0.0.0 <0.1.0
^0     := >=0.0.0 <1.0.0

semver's People

Contributors

steveklabnik avatar alexcrichton avatar globin avatar hone avatar burtonageo avatar opilar avatar brson avatar cruzbishop avatar mikrostew avatar richo avatar sfackler avatar muzikmoe avatar dirk avatar huonw avatar udoprog avatar omasanori avatar zzeroo avatar bjgill avatar dr-bonez avatar bors avatar sgrif avatar pcwalton avatar matklad avatar brendanzab avatar cgati avatar dtolnay avatar geal avatar errordeveloper avatar kamalmarhubi avatar kornelski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.