Sort messages prior to display (#56)

This commit is contained in:
Charlie Marsh 2022-08-31 10:53:35 -04:00 committed by GitHub
parent 3afedcd48b
commit 0ebed13e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::fmt;
use colored::Colorize;
@ -29,6 +30,22 @@ pub struct Message {
pub filename: String,
}
impl Ord for Message {
fn cmp(&self, other: &Self) -> Ordering {
(&self.filename, self.location.row(), self.location.column()).cmp(&(
&other.filename,
other.location.row(),
self.location.column(),
))
}
}
impl PartialOrd for Message {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Display for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(