usecrate::backport::*; usecrate::identifier::Identifier; usecrate::{BuildMetadata, Comparator, Prerelease, VersionReq}; use core::cmp::Ordering; use core::hash::{Hash, Hasher}; use core::iter::FromIterator; use core::ops::Deref;
impl Ord for Prerelease { fn cmp(&self, rhs: &Self) -> Ordering { matchself.is_empty() { trueif rhs.is_empty() => return Ordering::Equal, // A real release compares greater than prerelease. true => return Ordering::Greater, // Prerelease compares less than the real release. falseif rhs.is_empty() => return Ordering::Less, false => {}
}
let lhs = self.as_str().split('.'); letmut rhs = rhs.as_str().split('.');
for lhs in lhs { let rhs = match rhs.next() { // Spec: "A larger set of pre-release fields has a higher // precedence than a smaller set, if all of the preceding // identifiers are equal."
None => return Ordering::Greater,
Some(rhs) => rhs,
};
let string_cmp = || Ord::cmp(lhs, rhs); let is_ascii_digit = |b: u8| b.is_ascii_digit(); let ordering = match (
lhs.bytes().all(is_ascii_digit),
rhs.bytes().all(is_ascii_digit),
) { // Respect numeric ordering, for example 99 < 100. Spec says: // "Identifiers consisting of only digits are compared // numerically."
(true, true) => Ord::cmp(&lhs.len(), &rhs.len()).then_with(string_cmp), // Spec: "Numeric identifiers always have lower precedence than // non-numeric identifiers."
(true, false) => return Ordering::Less,
(false, true) => return Ordering::Greater, // Spec: "Identifiers with letters or hyphens are compared // lexically in ASCII sort order."
(false, false) => string_cmp(),
};
if ordering != Ordering::Equal { return ordering;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.