From 98babe10962be8fa3bcc22b973d460bf87eb4b53 Mon Sep 17 00:00:00 2001 From: Calastrophe Date: Tue, 19 Sep 2023 00:50:57 +0000 Subject: [PATCH] partial ord impl (#1473) --- packages/hooks/src/usestate.rs | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/hooks/src/usestate.rs b/packages/hooks/src/usestate.rs index 9e3fb5eed..a2da3c885 100644 --- a/packages/hooks/src/usestate.rs +++ b/packages/hooks/src/usestate.rs @@ -336,6 +336,50 @@ impl PartialEq> for UseState { } } +impl PartialOrd for UseState { + fn ge(&self, other: &T) -> bool { + *self.current_val >= *other + } + + fn gt(&self, other: &T) -> bool { + *self.current_val > *other + } + + fn le(&self, other: &T) -> bool { + *self.current_val <= *other + } + + fn lt(&self, other: &T) -> bool { + *self.current_val < *other + } + + fn partial_cmp(&self, other: &T) -> Option { + (*self.current_val).partial_cmp(other) + } +} + +impl PartialOrd> for UseState { + fn ge(&self, other: &UseState) -> bool { + self.current_val >= other.current_val + } + + fn gt(&self, other: &UseState) -> bool { + self.current_val > other.current_val + } + + fn le(&self, other: &UseState) -> bool { + self.current_val <= other.current_val + } + + fn lt(&self, other: &UseState) -> bool { + self.current_val < other.current_val + } + + fn partial_cmp(&self, other: &UseState) -> Option { + self.current_val.partial_cmp(&other.current_val) + } +} + impl Debug for UseState { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self.current_val)