forked from gluesql/gluesql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply binary_op macros to existing data types (gluesql#987)
- Loading branch information
Showing
10 changed files
with
131 additions
and
3,304 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use {crate::prelude::Value, rust_decimal::prelude::Decimal, std::cmp::Ordering}; | ||
|
||
super::macros::impl_try_binary_op!(I128, i128); | ||
#[cfg(test)] | ||
super::macros::generate_binary_op_tests!(I128, i128); | ||
|
||
impl PartialEq<Value> for i128 { | ||
fn eq(&self, other: &Value) -> bool { | ||
match other { | ||
I8(other) => (*self as i8) == *other, | ||
I16(other) => (*self as i16) == *other, | ||
I32(other) => (*self as i32) == *other, | ||
I64(other) => (*self as i64) == *other, | ||
I128(other) => self == other, | ||
U8(other) => *self == (*other as i128), | ||
U16(other) => *self == (*other as i128), | ||
F64(other) => ((*self as f64) - other).abs() < f64::EPSILON, | ||
Decimal(other) => Decimal::from(*self) == *other, | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
impl PartialOrd<Value> for i128 { | ||
fn partial_cmp(&self, other: &Value) -> Option<Ordering> { | ||
match other { | ||
I8(other) => (*self as i8).partial_cmp(other), | ||
I16(other) => (*self as i16).partial_cmp(other), | ||
I32(other) => (*self as i32).partial_cmp(other), | ||
I64(other) => (*self as i64).partial_cmp(other), | ||
I128(other) => self.partial_cmp(other), | ||
U8(other) => self.partial_cmp(&(*other as i128)), | ||
U16(other) => self.partial_cmp(&(*other as i128)), | ||
F64(other) => (*self as f64).partial_cmp(other), | ||
Decimal(other) => Decimal::from(*self).partial_cmp(other), | ||
_ => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use {crate::prelude::Value, rust_decimal::prelude::Decimal, std::cmp::Ordering}; | ||
|
||
super::macros::impl_try_binary_op!(I32, i32); | ||
#[cfg(test)] | ||
super::macros::generate_binary_op_tests!(I32, i32); | ||
|
||
impl PartialEq<Value> for i32 { | ||
fn eq(&self, other: &Value) -> bool { | ||
match other { | ||
I8(other) => (*self as i8) == *other, | ||
I16(other) => (*self as i16) == *other, | ||
I32(other) => self == other, | ||
I64(other) => (*self as i64) == *other, | ||
I128(other) => (*self as i128) == *other, | ||
U8(other) => *self == (*other as i32), | ||
U16(other) => *self == (*other as i32), | ||
F64(other) => ((*self as f64) - other).abs() < f64::EPSILON, | ||
Decimal(other) => Decimal::from(*self) == *other, | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
impl PartialOrd<Value> for i32 { | ||
fn partial_cmp(&self, other: &Value) -> Option<Ordering> { | ||
match other { | ||
I8(other) => (*self as i8).partial_cmp(other), | ||
I16(other) => (*self as i16).partial_cmp(other), | ||
I32(other) => self.partial_cmp(other), | ||
I64(other) => (*self as i64).partial_cmp(other), | ||
I128(other) => (*self as i128).partial_cmp(other), | ||
U8(other) => self.partial_cmp(&(*other as i32)), | ||
U16(other) => self.partial_cmp(&(*other as i32)), | ||
F64(other) => (*self as f64).partial_cmp(other), | ||
Decimal(other) => Decimal::from(*self).partial_cmp(other), | ||
_ => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use {crate::prelude::Value, rust_decimal::prelude::Decimal, std::cmp::Ordering}; | ||
|
||
super::macros::impl_try_binary_op!(I64, i64); | ||
#[cfg(test)] | ||
super::macros::generate_binary_op_tests!(I64, i64); | ||
|
||
impl PartialEq<Value> for i64 { | ||
fn eq(&self, other: &Value) -> bool { | ||
match other { | ||
I8(other) => (*self as i8) == *other, | ||
I16(other) => (*self as i16) == *other, | ||
I32(other) => (*self as i32) == *other, | ||
I64(other) => self == other, | ||
I128(other) => (*self as i128) == *other, | ||
U8(other) => *self == (*other as i64), | ||
U16(other) => *self == (*other as i64), | ||
F64(other) => ((*self as f64) - other).abs() < f64::EPSILON, | ||
Decimal(other) => Decimal::from(*self) == *other, | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
impl PartialOrd<Value> for i64 { | ||
fn partial_cmp(&self, other: &Value) -> Option<Ordering> { | ||
match other { | ||
I8(other) => (*self as i8).partial_cmp(other), | ||
I16(other) => (*self as i16).partial_cmp(other), | ||
I32(other) => (*self as i32).partial_cmp(other), | ||
I64(other) => self.partial_cmp(other), | ||
I128(other) => (*self as i128).partial_cmp(other), | ||
U8(other) => self.partial_cmp(&(*other as i64)), | ||
U16(other) => self.partial_cmp(&(*other as i64)), | ||
F64(other) => (*self as f64).partial_cmp(other), | ||
Decimal(other) => Decimal::from(*self).partial_cmp(other), | ||
_ => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
mod i128; | ||
mod i16; | ||
mod i32; | ||
mod i64; | ||
mod i8; | ||
mod u16; | ||
mod u8; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters