use crate::{
traits::{dyn_eq::DynEq, structural_eq::StructuralEq, value_eq::ValueEq},
values::{
core_value::CoreValue,
core_values::{
decimal::typed_decimal::TypedDecimal,
integer::typed_integer::TypedInteger,
},
},
};
impl StructuralEq for CoreValue {
fn structural_eq(&self, other: &Self) -> bool {
match (self, other) {
(CoreValue::Boolean(a), CoreValue::Boolean(b)) => {
a.structural_eq(b)
}
(CoreValue::Integer(a), CoreValue::Integer(b)) => {
a.structural_eq(b)
}
(CoreValue::TypedInteger(a), CoreValue::TypedInteger(b)) => {
a.structural_eq(b)
}
(CoreValue::Integer(a), CoreValue::TypedInteger(b))
| (CoreValue::TypedInteger(b), CoreValue::Integer(a)) => {
TypedInteger::IBig(a.clone()).structural_eq(b)
}
(CoreValue::Decimal(a), CoreValue::Decimal(b)) => {
a.structural_eq(b)
}
(CoreValue::TypedDecimal(a), CoreValue::TypedDecimal(b)) => {
a.structural_eq(b)
}
(CoreValue::Decimal(a), CoreValue::TypedDecimal(b))
| (CoreValue::TypedDecimal(b), CoreValue::Decimal(a)) => {
TypedDecimal::Decimal(a.clone()).structural_eq(b)
}
(CoreValue::Text(a), CoreValue::Text(b)) => a.structural_eq(b),
(CoreValue::Null, CoreValue::Null) => true,
(CoreValue::Endpoint(a), CoreValue::Endpoint(b)) => {
a.structural_eq(b)
}
(CoreValue::List(a), CoreValue::List(b)) => a.structural_eq(b),
(CoreValue::Map(a), CoreValue::Map(b)) => a.structural_eq(b),
(CoreValue::Type(a), CoreValue::Type(b)) => a.structural_eq(b),
(CoreValue::Callable(a), CoreValue::Callable(b)) => {
a.structural_eq(b)
}
(CoreValue::Range(a), CoreValue::Range(b)) => {
a.start.structural_eq(&b.start) && a.end.structural_eq(&b.end)
}
(CoreValue::Sender(s), CoreValue::Sender(t)) => s.structural_eq(t),
(CoreValue::Receiver(r), CoreValue::Receiver(t)) => {
r.structural_eq(t)
}
_ => false,
}
}
}
impl ValueEq for CoreValue {
fn value_eq(&self, other: &Self) -> bool {
match (self, other) {
(CoreValue::Decimal(a), CoreValue::Decimal(b)) => a.value_eq(b),
(CoreValue::TypedDecimal(a), CoreValue::TypedDecimal(b)) => {
a.value_eq(b)
}
_ => self == other,
}
}
}
impl PartialEq for CoreValue {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(CoreValue::Uninitialized, CoreValue::Uninitialized) => true,
(CoreValue::Null, CoreValue::Null) => true,
(CoreValue::Instant(i1), CoreValue::Instant(i2)) => i1 == i2,
(CoreValue::Boolean(b1), CoreValue::Boolean(b2)) => b1 == b2,
(CoreValue::Integer(i1), CoreValue::Integer(i2)) => i1 == i2,
(CoreValue::TypedInteger(ti1), CoreValue::TypedInteger(ti2)) => {
ti1 == ti2
}
(CoreValue::Decimal(d1), CoreValue::Decimal(d2)) => d1 == d2,
(CoreValue::TypedDecimal(td1), CoreValue::TypedDecimal(td2)) => {
td1 == td2
}
(CoreValue::Text(t1), CoreValue::Text(t2)) => t1 == t2,
(CoreValue::Endpoint(e1), CoreValue::Endpoint(e2)) => e1 == e2,
(CoreValue::List(l1), CoreValue::List(l2)) => l1 == l2,
(CoreValue::Map(m1), CoreValue::Map(m2)) => m1 == m2,
(CoreValue::Type(t1), CoreValue::Type(t2)) => t1 == t2,
(
CoreValue::EntityTypeDefinition(etd1),
CoreValue::EntityTypeDefinition(etd2),
) => etd1 == etd2,
(CoreValue::Callable(c1), CoreValue::Callable(c2)) => c1 == c2,
(CoreValue::Range(r1), CoreValue::Range(r2)) => r1 == r2,
(CoreValue::Box(b1), CoreValue::Box(b2)) => *b1 == *b2,
_ => false,
}
}
}
impl Eq for CoreValue {}
impl CoreValue {
#[allow(unused)]
fn dyn_eq_native(&self, native: &dyn DynEq) -> bool {
match self {
CoreValue::Boolean(v) => native.dyn_eq(v),
CoreValue::Integer(v) => native.dyn_eq(v),
CoreValue::TypedInteger(v) => native.dyn_eq(v),
CoreValue::Decimal(v) => native.dyn_eq(v),
CoreValue::TypedDecimal(v) => native.dyn_eq(v),
CoreValue::Text(v) => native.dyn_eq(v),
CoreValue::Endpoint(v) => native.dyn_eq(v),
CoreValue::List(v) => native.dyn_eq(v),
CoreValue::Map(v) => native.dyn_eq(v),
CoreValue::Type(v) => native.dyn_eq(v),
CoreValue::Callable(v) => native.dyn_eq(v),
CoreValue::Range(v) => native.dyn_eq(v),
CoreValue::Null => native.dyn_eq(&()), CoreValue::Instant(v) => native.dyn_eq(v),
CoreValue::Uninitialized => todo!(),
CoreValue::EntityTypeDefinition(_entity_type_definition) => todo!(),
CoreValue::Box(value_container) => value_container.dyn_eq(native), CoreValue::Sender(sender) => sender.dyn_eq(native),
CoreValue::Receiver(receiver) => receiver.dyn_eq(native),
}
}
}
#[cfg(test)]
mod tests {
}