summaryrefslogtreecommitdiffstats
path: root/vendor/semver/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/semver/src/lib.rs')
-rw-r--r--vendor/semver/src/lib.rs50
1 files changed, 49 insertions, 1 deletions
diff --git a/vendor/semver/src/lib.rs b/vendor/semver/src/lib.rs
index d2c4eb378..9fb125513 100644
--- a/vendor/semver/src/lib.rs
+++ b/vendor/semver/src/lib.rs
@@ -60,7 +60,7 @@
//!
//! [Specifying Dependencies]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html
-#![doc(html_root_url = "https://docs.rs/semver/1.0.18")]
+#![doc(html_root_url = "https://docs.rs/semver/1.0.20")]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(all(not(feature = "std"), not(no_alloc_crate)), no_std)]
#![cfg_attr(not(no_unsafe_op_in_unsafe_fn_lint), deny(unsafe_op_in_unsafe_fn))]
@@ -102,6 +102,7 @@ mod serde;
use crate::alloc::vec::Vec;
use crate::identifier::Identifier;
+use core::cmp::Ordering;
use core::str::FromStr;
#[allow(unused_imports)]
@@ -431,6 +432,53 @@ impl Version {
pub fn parse(text: &str) -> Result<Self, Error> {
Version::from_str(text)
}
+
+ /// Compare the major, minor, patch, and pre-release value of two versions,
+ /// disregarding build metadata. Versions that differ only in build metadata
+ /// are considered equal. This comparison is what the SemVer spec refers to
+ /// as "precedence".
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use semver::Version;
+ ///
+ /// let mut versions = [
+ /// "1.20.0+c144a98".parse::<Version>().unwrap(),
+ /// "1.20.0".parse().unwrap(),
+ /// "1.0.0".parse().unwrap(),
+ /// "1.0.0-alpha".parse().unwrap(),
+ /// "1.20.0+bc17664".parse().unwrap(),
+ /// ];
+ ///
+ /// // This is a stable sort, so it preserves the relative order of equal
+ /// // elements. The three 1.20.0 versions differ only in build metadata so
+ /// // they are not reordered relative to one another.
+ /// versions.sort_by(Version::cmp_precedence);
+ /// assert_eq!(versions, [
+ /// "1.0.0-alpha".parse().unwrap(),
+ /// "1.0.0".parse().unwrap(),
+ /// "1.20.0+c144a98".parse().unwrap(),
+ /// "1.20.0".parse().unwrap(),
+ /// "1.20.0+bc17664".parse().unwrap(),
+ /// ]);
+ ///
+ /// // Totally order the versions, including comparing the build metadata.
+ /// versions.sort();
+ /// assert_eq!(versions, [
+ /// "1.0.0-alpha".parse().unwrap(),
+ /// "1.0.0".parse().unwrap(),
+ /// "1.20.0".parse().unwrap(),
+ /// "1.20.0+bc17664".parse().unwrap(),
+ /// "1.20.0+c144a98".parse().unwrap(),
+ /// ]);
+ /// ```
+ pub fn cmp_precedence(&self, other: &Self) -> Ordering {
+ Ord::cmp(
+ &(self.major, self.minor, self.patch, &self.pre),
+ &(other.major, other.minor, other.patch, &other.pre),
+ )
+ }
}
impl VersionReq {