Skip to content

Commit 44f9c06

Browse files
author
Vincent Rouillé
committed
fix Element order between BigInt and Int
1 parent 782f1cc commit 44f9c06

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

foundationdb/src/tuple/element.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use super::{Bytes, Versionstamp};
33
use std::{borrow::Cow, cmp};
44

55
#[cfg(feature = "num-bigint")]
6-
use std::convert::TryInto;
6+
use num_bigint::Sign;
7+
#[cfg(feature = "num-bigint")]
8+
use std::convert::TryFrom;
79

810
#[derive(Clone, Debug)]
911
pub enum Element<'a> {
@@ -53,6 +55,16 @@ impl<'a, 'b> Ord for CmpElement<'a, 'b> {
5355
(Element::Int(a), Element::Int(b)) => a.cmp(b),
5456
#[cfg(feature = "num-bigint")]
5557
(Element::BigInt(a), Element::BigInt(b)) => a.cmp(b),
58+
#[cfg(feature = "num-bigint")]
59+
(Element::BigInt(a), Element::Int(b)) => match i64::try_from(a) {
60+
Ok(a) => a.cmp(b),
61+
Err(_) => a.sign().cmp(&Sign::NoSign),
62+
},
63+
#[cfg(feature = "num-bigint")]
64+
(Element::Int(a), Element::BigInt(b)) => match i64::try_from(b) {
65+
Ok(b) => a.cmp(&b),
66+
Err(_) => Sign::NoSign.cmp(&b.sign()),
67+
},
5668
(Element::Float(a), Element::Float(b)) => {
5769
f32_to_u32_be_bytes(*a).cmp(&f32_to_u32_be_bytes(*b))
5870
}
@@ -94,7 +106,7 @@ impl<'a> Element<'a> {
94106
Element::Tuple(_) => super::NESTED,
95107
Element::Int(_) => super::INTZERO,
96108
#[cfg(feature = "num-bigint")]
97-
Element::BigInt(_) => super::POSINTEND,
109+
Element::BigInt(_) => super::INTZERO,
98110
Element::Float(_) => super::FLOAT,
99111
Element::Double(_) => super::DOUBLE,
100112
Element::Bool(v) => {
@@ -167,7 +179,7 @@ impl<'a> Element<'a> {
167179
match self {
168180
Element::Int(v) => Some(*v),
169181
#[cfg(feature = "num-bigint")]
170-
Element::BigInt(v) => v.try_into().ok(),
182+
Element::BigInt(v) => i64::try_from(v).ok(),
171183
_ => None,
172184
}
173185
}

0 commit comments

Comments
 (0)