commit | 9c4727890d717418d3ccb8cc5a2d4b4432972a62 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <[email protected]> | Thu May 23 23:15:02 2024 +0000 |
committer | Android Build Coastguard Worker <[email protected]> | Thu May 23 23:15:02 2024 +0000 |
tree | 85647cdbc8b0deedf449a0692ef9fb7da1a2193f | |
parent | b188117b235c965354106b8e9afc300ea597af30 [diff] | |
parent | 7eed640af5a8ea4ad2a42d894c7aecf129423813 [diff] |
Snap for 11881322 from 7eed640af5a8ea4ad2a42d894c7aecf129423813 to 24Q3-release Change-Id: I28cac7fd09742a5a18297bd932089e989482ae80
A parser and evaluator for Cargo's flavor of Semantic Versioning.
Semantic Versioning (see https://semver.org) is a guideline for how version numbers are assigned and incremented. It is widely followed within the Cargo/crates.io ecosystem for Rust.
[dependencies] semver = "1.0"
Compiler support: requires rustc 1.31+
use semver::{BuildMetadata, Prerelease, Version, VersionReq}; fn main() { let req = VersionReq::parse(">=1.2.3, <1.8.0").unwrap(); // Check whether this requirement matches version 1.2.3-alpha.1 (no) let version = Version { major: 1, minor: 2, patch: 3, pre: Prerelease::new("alpha.1").unwrap(), build: BuildMetadata::EMPTY, }; assert!(!req.matches(&version)); // Check whether it matches 1.3.0 (yes it does) let version = Version::parse("1.3.0").unwrap(); assert!(req.matches(&version)); }
Besides Cargo, several other package ecosystems and package managers for other languages also use SemVer: RubyGems/Bundler for Ruby, npm for JavaScript, Composer for PHP, CocoaPods for Objective-C...
The semver
crate is specifically intended to implement Cargo's interpretation of Semantic Versioning.
Where the various tools differ in their interpretation or implementation of the spec, this crate follows the implementation choices made by Cargo. If you are operating on version numbers from some other package ecosystem, you will want to use a different semver library which is appropriate to that ecosystem.
The extent of Cargo's SemVer support is documented in the Specifying Dependencies chapter of the Cargo reference.