From 8828074e7c7bbb7325204279baebcfc2a5723083 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Sat, 2 Mar 2024 11:04:33 +1300 Subject: [PATCH] impl Ord for Event --- chorus-lib/src/types/event/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/chorus-lib/src/types/event/mod.rs b/chorus-lib/src/types/event/mod.rs index b277cc5..593a950 100644 --- a/chorus-lib/src/types/event/mod.rs +++ b/chorus-lib/src/types/event/mod.rs @@ -1,6 +1,7 @@ use super::{Id, Kind, Pubkey, Sig, Tags, Time}; use crate::error::{ChorusError, Error}; use crate::types::parse::json_escape::json_escape; +use std::cmp::Ordering; use std::fmt; mod json_event; @@ -178,6 +179,20 @@ impl fmt::Display for Event<'_> { } } +impl Eq for Event<'_> {} + +impl PartialOrd for Event<'_> { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Event<'_> { + fn cmp(&self, other: &Self) -> Ordering { + self.created_at().cmp(&other.created_at()) + } +} + #[derive(Debug, Clone)] pub struct OwnedEvent(pub Vec);