Skip to content

Commit

Permalink
Derive PartialOrs/Ord for task
Browse files Browse the repository at this point in the history
  • Loading branch information
sanpii committed Feb 8, 2023
1 parent f716187 commit 904455f
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions src/tasks/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Task {
inner: todo_txt::task::Extended,
pub id: usize,
Expand Down Expand Up @@ -72,30 +72,6 @@ impl std::fmt::Display for Task {
}
}

impl std::cmp::PartialOrd for Task {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl std::cmp::Ord for Task {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
if self.inner.due_date != other.inner.due_date {
return self.inner.due_date.cmp(&other.inner.due_date);
}

if self.inner.priority != other.inner.priority {
return self.inner.priority.cmp(&other.inner.priority).reverse();
}

if self.inner.subject != other.inner.subject {
return self.inner.subject.cmp(&other.inner.subject);
}

std::cmp::Ordering::Equal
}
}

#[cfg(test)]
mod tests {
use crate::tasks::task::*;
Expand Down

0 comments on commit 904455f

Please sign in to comment.