pub struct VersionReq { /* private fields */ }Expand description
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.
§Examples
use helpers4::version::{Version, VersionReq};
let req = VersionReq::parse("^1.2")?;
assert!(req.matches(&Version::parse("1.9.0")?));
assert!(!req.matches(&Version::parse("2.0.0")?));
assert!(!req.matches(&Version::parse("1.1.9")?));
let range = VersionReq::parse(">=1.0, <1.5")?;
assert!(range.matches(&Version::parse("1.4.9")?));Implementations§
Source§impl VersionReq
impl VersionReq
Sourcepub fn parse(text: &str) -> Result<Self, ParseVersionError>
pub fn parse(text: &str) -> Result<Self, ParseVersionError>
Parses a requirement.
§Arguments
text- The requirement, such as"^1.2",">=1.0, <2.0"or"*".
§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.