Version
A Semantic Versioning 2.0.0 version: MAJOR.MINOR.PATCH, optionally
with a pre-release (-alpha.1) and build metadata (+sha.5114f85).
Version::parse is strict semver; Version::parse_lenient also takes v1.2. Versions
order by semver precedence (a pre-release sorts before its release, numeric identifiers
compare as numbers); build metadata does not count for precedence
(precedence) but breaks ties in Ord so that it stays consistent with
Eq.
Import
Section titled “Import”Cargo feature version (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”A release version, with no pre-release or build metadata.
Parameters
| Parameter | Type | Description |
|---|---|---|
major | u64 | The major version. |
minor | u64 | The minor version. |
patch | u64 | The patch version. |
Returns
Self — The version major.minor.patch.
Parses a strict semver version: exactly MAJOR.MINOR.PATCH, then optionally -PRERELEASE
and +BUILD. No v prefix, no missing parts, no leading zeros in the numbers.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | &str | The version to parse. |
Returns
Result<Self, ParseVersionError>
Errors
A ParseVersionError naming what is wrong: an empty text, a missing or invalid number,
a leading zero, or a bad pre-release or build identifier.
parse_lenient
Section titled “parse_lenient”Parses a version the way people write it: surrounding whitespace and a leading v or V
are ignored, and a missing minor or patch is 0 ("v1.2" is 1.2.0, "3" is 3.0.0).
Parameters
| Parameter | Type | Description |
|---|---|---|
text | &str | The version to parse. |
Returns
Result<Self, ParseVersionError>
Errors
The same ParseVersionErrors as Version::parse, except that a missing minor or
patch is not an error.
The major version.
Returns
u64 — The first number.
The minor version.
Returns
u64 — The second number.
The patch version.
Returns
u64 — The third number.
The pre-release identifiers, without the leading -.
Returns
Option<&str> — For instance Some("alpha.1"), or None for a release.
The build metadata, without the leading +.
Returns
Option<&str> — For instance Some("sha.5114f85"), or None.
is_prerelease
Section titled “is_prerelease”Whether this is a pre-release (it has a -... part).
Returns
bool — true for 1.0.0-alpha, false for 1.0.0.
bump_major
Section titled “bump_major”The next major version: 1.4.2-rc.1 gives 2.0.0.
Returns
Self — A release with the major version incremented and the rest reset. It saturates at
u64::MAX instead of overflowing.
bump_minor
Section titled “bump_minor”The next minor version: 1.4.2-rc.1 gives 1.5.0.
Returns
Self — A release with the minor version incremented and the patch reset. It saturates at
u64::MAX instead of overflowing.
bump_patch
Section titled “bump_patch”The next patch version: 1.4.2-rc.1 gives 1.4.3.
Returns
Self — A release with the patch version incremented. It saturates at u64::MAX instead of
overflowing.
precedence
Section titled “precedence”Compares two versions by semver precedence: build metadata is ignored, so 1.0.0+a and
1.0.0+b are equal here.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | &Self | The version to compare with. |
Returns
Ordering — How this version orders relative to other.
Error type: ParseVersionError
Section titled “Error type: ParseVersionError”Why a version or a version requirement could not be parsed.
