VersionReq
A version requirement such as ^1.2, >=1.0, <2.0 or 1.*: which versions are acceptable.
The syntax and the rules are Cargo’s. A requirement is comma-separated comparators that must
all match. Operators: =, >, >=, <, <=, ~ (tilde: patch-level changes, or minor when
the patch is omitted), ^ (caret: changes that keep the left-most non-zero number), and none,
which means caret. 1, 1.2 and 1.2.3 may be partial; *, x and X are wildcards
(1.*, 1.2.x, or * alone for anything). A pre-release version only matches a
requirement that names a pre-release of the same MAJOR.MINOR.PATCH.
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”Parses a requirement.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | &str | The requirement, such as "^1.2", ">=1.0, <2.0" or "*". |
Returns
Result<Self, ParseVersionError>
Errors
A ParseVersionError: Empty for an empty text,
InvalidComparator for a malformed comparator
(unknown operator, a wildcard with an operator other than =, a pre-release on a partial
version, build metadata), or the number and identifier errors of Version::parse.
matches
Section titled “matches”Whether version satisfies every comparator (and the pre-release rule).
Parameters
| Parameter | Type | Description |
|---|---|---|
version | &Version | The version to check. |
Returns
bool — true when the version is acceptable.
Error type: ParseVersionError
Section titled “Error type: ParseVersionError”Why a version or a version requirement could not be parsed.
