]> git.proxmox.com Git - rustc.git/blame - vendor/semver-0.11.0/README.md
New upstream version 1.59.0+dfsg1
[rustc.git] / vendor / semver-0.11.0 / README.md
CommitLineData
f20569fa
XL
1semver\r
2======\r
3\r
4Semantic version parsing and comparison.\r
5\r
6![Build Status](https://github.com/steveklabnik/semver/workflows/CI/badge.svg)\r
7\r
8[Documentation](https://steveklabnik.github.io/semver)\r
9\r
10Semantic versioning (see https://semver.org/) is a set of rules for\r
11assigning version numbers.\r
12\r
13## SemVer and the Rust ecosystem\r
14\r
15Rust itself follows the SemVer specification, as does its standard libraries. The two are\r
16not tied together.\r
17\r
18[Cargo](https://crates.io), Rust's package manager, uses SemVer to determine which versions of\r
19packages you need installed.\r
20\r
21## Installation\r
22\r
23To use `semver`, add this to your `[dependencies]` section:\r
24\r
25```toml\r
26semver = "0.9.0"\r
27```\r
28\r
29And this to your crate root:\r
30\r
31```rust\r
32extern crate semver;\r
33```\r
34\r
35## Versions\r
36\r
37At its simplest, the `semver` crate allows you to construct `Version` objects using the `parse`\r
38method:\r
39\r
40```rust\r
41use semver::Version;\r
42\r
43assert!(Version::parse("1.2.3") == Ok(Version {\r
44 major: 1,\r
45 minor: 2,\r
46 patch: 3,\r
47 pre: vec!(),\r
48 build: vec!(),\r
49}));\r
50```\r
51\r
52If you have multiple `Version`s, you can use the usual comparison operators to compare them:\r
53\r
54```rust\r
55use semver::Version;\r
56\r
57assert!(Version::parse("1.2.3-alpha") != Version::parse("1.2.3-beta"));\r
58assert!(Version::parse("1.2.3-alpha2") > Version::parse("1.2.0"));\r
59```\r
60\r
61## Requirements\r
62\r
63The `semver` crate also provides the ability to compare requirements, which are more complex\r
64comparisons.\r
65\r
66For example, creating a requirement that only matches versions greater than or\r
67equal to 1.0.0:\r
68\r
69```rust\r
70use semver::Version;\r
71use semver::VersionReq;\r
72\r
73let r = VersionReq::parse(">= 1.0.0").unwrap();\r
74let v = Version::parse("1.0.0").unwrap();\r
75\r
76assert!(r.to_string() == ">= 1.0.0".to_string());\r
77assert!(r.matches(&v))\r
78```\r
79\r
80It also allows parsing of `~x.y.z` and `^x.y.z` requirements as defined at\r
81https://www.npmjs.com/package/semver\r
82\r
83**Tilde requirements** specify a minimal version with some updates:\r
84\r
85```notrust\r
86~1.2.3 := >=1.2.3 <1.3.0\r
87~1.2 := >=1.2.0 <1.3.0\r
88~1 := >=1.0.0 <2.0.0\r
89```\r
90\r
91**Caret requirements** allow SemVer compatible updates to a specified version,\r
92`0.x` and `0.x+1` are not considered compatible, but `1.x` and `1.x+1` are.\r
93\r
94`0.0.x` is not considered compatible with any other version.\r
95Missing minor and patch versions are desugared to `0` but allow flexibility for that value.\r
96\r
97```notrust\r
98^1.2.3 := >=1.2.3 <2.0.0\r
99^0.2.3 := >=0.2.3 <0.3.0\r
100^0.0.3 := >=0.0.3 <0.0.4\r
101^0.0 := >=0.0.0 <0.1.0\r
102^0 := >=0.0.0 <1.0.0\r
103```\r