0.4.11: IconInfo sort also by type
This commit is contained in:
parent
640e986ef5
commit
1d3fd63754
3 changed files with 30 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1638,7 +1638,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
|||
|
||||
[[package]]
|
||||
name = "site_icons"
|
||||
version = "0.4.10"
|
||||
version = "0.4.11"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "site_icons"
|
||||
version = "0.4.10"
|
||||
version = "0.4.11"
|
||||
authors = ["Sam Denty <sam@samdenty.com>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0"
|
||||
|
|
|
@ -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!(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue