0.4.11: IconInfo sort also by type

This commit is contained in:
Sam Denty 2022-12-26 22:56:55 +00:00
parent 640e986ef5
commit 1d3fd63754
No known key found for this signature in database
GPG key ID: 7B4EAF7B9E291B79
3 changed files with 30 additions and 12 deletions

2
Cargo.lock generated
View file

@ -1638,7 +1638,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]] [[package]]
name = "site_icons" name = "site_icons"
version = "0.4.10" version = "0.4.11"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"clap", "clap",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "site_icons" name = "site_icons"
version = "0.4.10" version = "0.4.11"
authors = ["Sam Denty <sam@samdenty.com>"] authors = ["Sam Denty <sam@samdenty.com>"]
edition = "2018" edition = "2018"
license = "GPL-3.0" license = "GPL-3.0"

View file

@ -176,17 +176,35 @@ impl Display for IconInfo {
impl Ord for IconInfo { impl Ord for IconInfo {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
let this_size = self.size(); match (self, other) {
let other_size = other.size(); (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 let this_size = self.size().unwrap();
} else if let (Some(this_size), Some(other_size)) = (this_size, other_size) { let other_size = other.size().unwrap();
this_size.cmp(other_size)
} else if this_size.is_none() { this_size.cmp(other_size).then_with(|| match (self, other) {
Ordering::Less (IconInfo::PNG { .. }, IconInfo::PNG { .. }) => Ordering::Equal,
} else { (IconInfo::PNG { .. }, _) => Ordering::Less,
Ordering::Greater (_, 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!(),
})
}
} }
} }
} }