Simplify integer and float functions trait bounds

This commit is contained in:
Kerollmops 2021-04-07 11:57:16 +02:00
parent efbfa81fa7
commit 51767725b2
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
17 changed files with 217 additions and 521 deletions

View file

@ -33,7 +33,7 @@ impl From<OrderedFloat<f64>> for FacetValue {
impl From<i64> for FacetValue {
fn from(integer: i64) -> FacetValue {
FacetValue::Number(integer as f64)
FacetValue::Number(OrderedFloat(integer as f64))
}
}

View file

@ -13,16 +13,6 @@ pub fn f64_into_bytes(float: f64) -> Option<[u8; 8]> {
None
}
#[inline]
pub fn i64_into_bytes(int: i64) -> [u8; 8] {
xor_first_bit(int.to_be_bytes())
}
#[inline]
pub fn i64_from_bytes(bytes: [u8; 8]) -> i64 {
i64::from_be_bytes(xor_first_bit(bytes))
}
#[inline]
fn xor_first_bit(mut x: [u8; 8]) -> [u8; 8] {
x[0] ^= 0x80;
@ -55,15 +45,4 @@ mod tests {
let vec: Vec<_> = [a, b, c, d, e].iter().cloned().map(f64_into_bytes).collect();
assert!(is_sorted(&vec), "{:?}", vec);
}
#[test]
fn ordered_i64_bytes() {
let a = -10_i64;
let b = -0_i64;
let c = 1_i64;
let d = 43_i64;
let vec: Vec<_> = [a, b, c, d].iter().cloned().map(i64_into_bytes).collect();
assert!(is_sorted(&vec), "{:?}", vec);
}
}