From 1cc8cfe0d4b2229e7db216396deb7d752c0a67a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Volf?= Date: Mon, 9 Sep 2024 18:49:28 +0200 Subject: [PATCH] feat: implement `Ord` for the subtask model --- src/models/subtask.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/models/subtask.rs b/src/models/subtask.rs index 7aa9e84..ab15e63 100644 --- a/src/models/subtask.rs +++ b/src/models/subtask.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use crate::models::task::Task; use crate::schema::subtasks; use chrono::NaiveDateTime; @@ -48,6 +49,21 @@ impl Subtask { } } +impl Eq for Subtask {} + +impl PartialOrd for Subtask { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Subtask { + fn cmp(&self, other: &Self) -> Ordering { + self.is_completed().cmp(&other.is_completed()) + .then(self.created_at().cmp(&other.created_at())) + } +} + #[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)] #[diesel(table_name = subtasks)] pub struct NewSubtask {