diff --git a/grovedb/src/batch/key_info.rs b/grovedb/src/batch/key_info.rs index 19bea9e2..a8eb50af 100644 --- a/grovedb/src/batch/key_info.rs +++ b/grovedb/src/batch/key_info.rs @@ -100,20 +100,7 @@ impl PartialEq<&[u8]> for KeyInfo { #[cfg(feature = "full")] impl PartialOrd for KeyInfo { fn partial_cmp(&self, other: &Self) -> Option { - match self.as_slice().partial_cmp(other.as_slice()) { - None => None, - Some(ord) => match ord { - Ordering::Less => Some(Ordering::Less), - Ordering::Equal => { - let other_len = other.max_length(); - match self.max_length().partial_cmp(&other_len) { - None => Some(Ordering::Equal), - Some(ord) => Some(ord), - } - } - Ordering::Greater => Some(Ordering::Greater), - }, - } + Some(self.cmp(other)) } } diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index a3b2d502..9724ea7b 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -168,19 +168,19 @@ pub enum Op { impl PartialOrd for Op { fn partial_cmp(&self, other: &Self) -> Option { - match (self, other) { - (Op::Delete, Op::Insert { .. }) => Some(Ordering::Less), - (Op::Delete, Op::Replace { .. }) => Some(Ordering::Less), - (Op::Insert { .. }, Op::Delete) => Some(Ordering::Greater), - (Op::Replace { .. }, Op::Delete) => Some(Ordering::Greater), - _ => Some(Ordering::Equal), - } + Some(self.cmp(other)) } } impl Ord for Op { fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other).expect("all ops have order") + match (self, other) { + (Op::Delete, Op::Insert { .. }) => Ordering::Less, + (Op::Delete, Op::Replace { .. }) => Ordering::Less, + (Op::Insert { .. }, Op::Delete) => Ordering::Greater, + (Op::Replace { .. }, Op::Delete) => Ordering::Greater, + _ => Ordering::Equal, + } } }