Skip to content

Commit

Permalink
a bit less Reverse and less double negatives
Browse files Browse the repository at this point in the history
Signed-off-by: clux <sszynrae@gmail.com>
  • Loading branch information
clux committed Dec 22, 2021
1 parent 3082efa commit e8061ff
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions kube-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,25 @@ impl FromStr for Version {
// A key used to allow sorting Versions
#[derive(PartialEq, Eq, PartialOrd, Ord)]
enum VersionSortKey<'a> {
Stable(Reverse<u32>),
Beta(Reverse<u32>, Reverse<Option<u32>>),
Alpha(Reverse<u32>, Reverse<Option<u32>>),
Nonconformant(&'a str),
Nonconformant(Reverse<&'a str>),
Alpha(u32, Option<u32>),
Beta(u32, Option<u32>),
Stable(u32),
}
impl Version {
fn to_sort_key(&self) -> VersionSortKey {
match self {
Version::Stable(v) => VersionSortKey::Stable(Reverse(*v)),
Version::Beta(v, beta) => VersionSortKey::Beta(Reverse(*v), Reverse(*beta)),
Version::Alpha(v, alpha) => VersionSortKey::Alpha(Reverse(*v), Reverse(*alpha)),
Version::Nonconformant(nc) => VersionSortKey::Nonconformant(nc),
Version::Stable(v) => VersionSortKey::Stable(*v),
Version::Beta(v, beta) => VersionSortKey::Beta(*v, *beta),
Version::Alpha(v, alpha) => VersionSortKey::Alpha(*v, *alpha),
Version::Nonconformant(nc) => VersionSortKey::Nonconformant(Reverse(nc)),
}
}
}

impl Ord for Version {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
other.to_sort_key().cmp(&self.to_sort_key())
self.to_sort_key().cmp(&other.to_sort_key())
}
}

Expand Down

0 comments on commit e8061ff

Please sign in to comment.