From 7bb9fcd17c91d8bdd2487c33c0acf887f5ee4dfe Mon Sep 17 00:00:00 2001 From: ripytide Date: Sat, 1 Apr 2023 17:11:13 +0100 Subject: [PATCH] redid the custom_ord_wrapper to just take a Fn rather than a new trait --- src/custom_ord_wrapper.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/custom_ord_wrapper.rs b/src/custom_ord_wrapper.rs index 3a7835c..2e92406 100644 --- a/src/custom_ord_wrapper.rs +++ b/src/custom_ord_wrapper.rs @@ -19,10 +19,6 @@ along with range_bounds_map. If not, see . use std::cmp::Ordering; -pub trait CustomOrd { - fn cmp(&self, a: &T) -> Ordering; -} - pub enum CustomOrdWrapper { CustomOrd(C), Value(T), @@ -30,18 +26,18 @@ pub enum CustomOrdWrapper { impl Ord for CustomOrdWrapper where - C: CustomOrd, + C: Fn(&T) -> Ordering, { fn cmp(&self, other: &Self) -> Ordering { match (self, other) { ( CustomOrdWrapper::CustomOrd(custom_ord), CustomOrdWrapper::Value(value), - ) => custom_ord.cmp(value), + ) => custom_ord(value), ( CustomOrdWrapper::Value(value), CustomOrdWrapper::CustomOrd(custom_ord), - ) => custom_ord.cmp(value), + ) => custom_ord(value), _ => panic!( "You must have exactly ONE Value and ONE CustomOrd when comparing CustomOrdWrapper's" ), @@ -51,18 +47,18 @@ where impl PartialOrd for CustomOrdWrapper where - C: CustomOrd, + C: Fn(&T) -> Ordering, { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl Eq for CustomOrdWrapper where C: CustomOrd {} +impl Eq for CustomOrdWrapper where C: Fn(&T) -> Ordering {} impl PartialEq for CustomOrdWrapper where - C: CustomOrd, + C: Fn(&T) -> Ordering, { fn eq(&self, other: &Self) -> bool { self.cmp(other).is_eq()