Skip to content

Commit

Permalink
Remove macro-exports in data/../macros (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
ever0de authored Oct 22, 2022
1 parent 29e9bd2 commit 75cf370
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
10 changes: 3 additions & 7 deletions core/src/data/value/binary_op/integer/i16.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use {
crate::{impl_try_binary_op, prelude::Value},
rust_decimal::prelude::Decimal,
std::cmp::Ordering,
};
use {crate::prelude::Value, rust_decimal::prelude::Decimal, std::cmp::Ordering};

impl_try_binary_op!(I16, i16);
super::macros::impl_try_binary_op!(I16, i16);
#[cfg(test)]
crate::generate_binary_op_tests!(I16, i16);
super::macros::generate_binary_op_tests!(I16, i16);

impl PartialEq<Value> for i16 {
fn eq(&self, other: &Value) -> bool {
Expand Down
10 changes: 3 additions & 7 deletions core/src/data/value/binary_op/integer/i8.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use {
crate::{impl_try_binary_op, prelude::Value},
rust_decimal::prelude::Decimal,
std::cmp::Ordering,
};
use {crate::prelude::Value, rust_decimal::prelude::Decimal, std::cmp::Ordering};

impl_try_binary_op!(I8, i8);
super::macros::impl_try_binary_op!(I8, i8);
#[cfg(test)]
crate::generate_binary_op_tests!(I8, i8);
super::macros::generate_binary_op_tests!(I8, i8);

impl PartialEq<Value> for i8 {
fn eq(&self, other: &Value) -> bool {
Expand Down
23 changes: 12 additions & 11 deletions core/src/data/value/binary_op/integer/macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[macro_export]
macro_rules! impl_interval_method {
(checked_mul, $lhs_variant: ident, $op: ident, $lhs: ident, $rhs: ident) => {
return Ok(Value::Interval($lhs * $rhs))
Expand All @@ -13,7 +12,6 @@ macro_rules! impl_interval_method {
};
}

#[macro_export]
macro_rules! impl_method {
($lhs_variant: ident, $lhs_primitive: ident, $lhs: ident, $method: ident, $op: ident, $rhs: ident) => {{
match *$rhs {
Expand Down Expand Up @@ -99,7 +97,7 @@ macro_rules! impl_method {
}),
Null => return Ok(Null),
Interval(rhs) => {
$crate::impl_interval_method!($method, $lhs_variant, $op, $lhs, rhs);
super::macros::impl_interval_method!($method, $lhs_variant, $op, $lhs, rhs);
}
_ => Err(ValueError::NonNumericMathOperation {
lhs: $lhs_variant($lhs),
Expand All @@ -112,7 +110,6 @@ macro_rules! impl_method {
}};
}

#[macro_export]
macro_rules! impl_try_binary_op {
($variant: ident, $primitive: ident) => {
use $crate::{
Expand All @@ -129,34 +126,33 @@ macro_rules! impl_try_binary_op {

fn try_add(&self, rhs: &Self::Rhs) -> Result<Value> {
let lhs = *self;
$crate::impl_method!($variant, $primitive, lhs, checked_add, Add, rhs)
super::macros::impl_method!($variant, $primitive, lhs, checked_add, Add, rhs)
}

fn try_subtract(&self, rhs: &Self::Rhs) -> Result<Value> {
let lhs = *self;
$crate::impl_method!($variant, $primitive, lhs, checked_sub, Subtract, rhs)
super::macros::impl_method!($variant, $primitive, lhs, checked_sub, Subtract, rhs)
}

fn try_multiply(&self, rhs: &Self::Rhs) -> Result<Value> {
let lhs = *self;
$crate::impl_method!($variant, $primitive, lhs, checked_mul, Multiply, rhs)
super::macros::impl_method!($variant, $primitive, lhs, checked_mul, Multiply, rhs)
}

fn try_divide(&self, rhs: &Self::Rhs) -> Result<Value> {
let lhs = *self;
$crate::impl_method!($variant, $primitive, lhs, checked_div, Divide, rhs)
super::macros::impl_method!($variant, $primitive, lhs, checked_div, Divide, rhs)
}

fn try_modulo(&self, rhs: &Self::Rhs) -> Result<Value> {
let lhs = *self;
$crate::impl_method!($variant, $primitive, lhs, checked_rem, Modulo, rhs)
super::macros::impl_method!($variant, $primitive, lhs, checked_rem, Modulo, rhs)
}
}
};
}

#[cfg(test)]
#[macro_export]
macro_rules! generate_binary_op_tests {
($variant: ident, $primitive: ident) => {
mod tests {
Expand Down Expand Up @@ -229,7 +225,6 @@ macro_rules! generate_binary_op_tests {
assert_eq!(base.partial_cmp(&I64(1)), Some(Ordering::Equal));
assert_eq!(base.partial_cmp(&I128(1)), Some(Ordering::Equal));
assert_eq!(base.partial_cmp(&U8(1)), Some(Ordering::Equal));
assert_eq!(base.partial_cmp(&F64(1.0)), Some(Ordering::Equal));

assert_eq!(
base.partial_cmp(&Decimal(Decimal::TWO)),
Expand Down Expand Up @@ -556,3 +551,9 @@ macro_rules! generate_binary_op_tests {
}
};
}

#[cfg(test)]
pub(crate) use generate_binary_op_tests;
pub(crate) use impl_interval_method;
pub(crate) use impl_method;
pub(crate) use impl_try_binary_op;
10 changes: 3 additions & 7 deletions core/src/data/value/binary_op/integer/u8.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use {
crate::{impl_try_binary_op, prelude::Value},
rust_decimal::prelude::Decimal,
std::cmp::Ordering,
};
use {crate::prelude::Value, rust_decimal::prelude::Decimal, std::cmp::Ordering};

impl_try_binary_op!(U8, u8);
super::macros::impl_try_binary_op!(U8, u8);
#[cfg(test)]
crate::generate_binary_op_tests!(U8, u8);
super::macros::generate_binary_op_tests!(U8, u8);

impl PartialEq<Value> for u8 {
fn eq(&self, other: &Value) -> bool {
Expand Down

0 comments on commit 75cf370

Please sign in to comment.