fix bad order implementation causing panic

This commit is contained in:
Mark 2024-10-13 16:43:48 +02:00
parent 4549a8d360
commit 14660b6dae

View File

@ -107,16 +107,18 @@ fn main() {
let mut prev_perc = 999; let mut prev_perc = 999;
songs.sort_by(|(path1, _, tags1), (path2, _, tags2)| { songs.sort_by(|(path1, _, tags1), (path2, _, tags2)| {
// Sort by Disc->Track->Path // Sort by Disc->Track->Path
if let (Some(d1), Some(d2)) = (tags1.disc(), tags2.disc()) { match (tags1.disc(), tags2.disc()) {
d1.cmp(&d2) (Some(d1), Some(d2)) => d1.cmp(&d2),
} else { (Some(_), None) => Ordering::Greater,
Ordering::Equal (None, Some(_)) => Ordering::Less,
(None, None) => Ordering::Equal,
} }
.then_with(|| { .then_with(|| {
if let (Some(t1), Some(t2)) = (tags1.track(), tags2.track()) { match (tags1.track(), tags2.track()) {
t1.cmp(&t2) (Some(t1), Some(t2)) => t1.cmp(&t2),
} else { (Some(_), None) => Ordering::Greater,
Ordering::Equal (None, Some(_)) => Ordering::Less,
(None, None) => Ordering::Equal,
} }
.then_with(|| path1.cmp(&path2)) .then_with(|| path1.cmp(&path2))
}) })