diff --git a/Cargo.lock b/Cargo.lock index 37e6576..a29e189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1638,7 +1638,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "site_icons" -version = "0.4.10" +version = "0.4.11" dependencies = [ "byteorder", "clap", diff --git a/Cargo.toml b/Cargo.toml index 54bec83..7677b77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "site_icons" -version = "0.4.10" +version = "0.4.11" authors = ["Sam Denty "] edition = "2018" license = "GPL-3.0" diff --git a/src/icon_info.rs b/src/icon_info.rs index b08a2ec..9f7bf07 100644 --- a/src/icon_info.rs +++ b/src/icon_info.rs @@ -176,17 +176,35 @@ impl Display for IconInfo { impl Ord for IconInfo { fn cmp(&self, other: &Self) -> Ordering { - let this_size = self.size(); - let other_size = other.size(); + match (self, other) { + (IconInfo::SVG, IconInfo::SVG) => Ordering::Equal, + (IconInfo::SVG, _) => Ordering::Less, + (_, IconInfo::SVG) => Ordering::Greater, - if this_size.is_none() && other_size.is_none() { - Ordering::Equal - } else if let (Some(this_size), Some(other_size)) = (this_size, other_size) { - this_size.cmp(other_size) - } else if this_size.is_none() { - Ordering::Less - } else { - Ordering::Greater + _ => { + let this_size = self.size().unwrap(); + let other_size = other.size().unwrap(); + + this_size.cmp(other_size).then_with(|| match (self, other) { + (IconInfo::PNG { .. }, IconInfo::PNG { .. }) => Ordering::Equal, + (IconInfo::PNG { .. }, _) => Ordering::Less, + (_, IconInfo::PNG { .. }) => Ordering::Greater, + + (IconInfo::GIF { .. }, IconInfo::GIF { .. }) => Ordering::Equal, + (IconInfo::GIF { .. }, _) => Ordering::Less, + (_, IconInfo::GIF { .. }) => Ordering::Greater, + + (IconInfo::JPEG { .. }, IconInfo::JPEG { .. }) => Ordering::Equal, + (IconInfo::JPEG { .. }, _) => Ordering::Less, + (_, IconInfo::JPEG { .. }) => Ordering::Greater, + + (IconInfo::ICO { .. }, IconInfo::ICO { .. }) => Ordering::Equal, + (IconInfo::ICO { .. }, _) => Ordering::Less, + (_, IconInfo::ICO { .. }) => Ordering::Greater, + + _ => unreachable!(), + }) + } } } }