use super::Numeric;
#[diagnostic::on_unimplemented(
message = "arithmetic between `{Self}` and `{Rhs}` is not supported",
label = "both operands must be Numeric (Int, BigInt, Float, Double, etc.)"
)]
pub trait ArithmeticOutput<Rhs: Numeric = Self>: Numeric {
type Output: Numeric;
}
use crate::sqlite::types::{Integer, Numeric as SqliteNumeric, Real};
impl ArithmeticOutput<Self> for Integer {
type Output = Self;
}
impl ArithmeticOutput<Real> for Integer {
type Output = Real;
}
impl ArithmeticOutput<SqliteNumeric> for Integer {
type Output = SqliteNumeric;
}
impl ArithmeticOutput<Integer> for Real {
type Output = Self;
}
impl ArithmeticOutput<Self> for Real {
type Output = Self;
}
impl ArithmeticOutput<SqliteNumeric> for Real {
type Output = Self;
}
impl ArithmeticOutput<Integer> for SqliteNumeric {
type Output = Self;
}
impl ArithmeticOutput<Real> for SqliteNumeric {
type Output = Real;
}
impl ArithmeticOutput<Self> for SqliteNumeric {
type Output = Self;
}
use crate::sqlite::types::Any as SqliteAny;
impl ArithmeticOutput<Self> for SqliteAny {
type Output = Self;
}
impl ArithmeticOutput<Integer> for SqliteAny {
type Output = Self;
}
impl ArithmeticOutput<Real> for SqliteAny {
type Output = Self;
}
impl ArithmeticOutput<SqliteNumeric> for SqliteAny {
type Output = Self;
}
impl ArithmeticOutput<SqliteAny> for Integer {
type Output = SqliteAny;
}
impl ArithmeticOutput<SqliteAny> for Real {
type Output = SqliteAny;
}
impl ArithmeticOutput<SqliteAny> for SqliteNumeric {
type Output = SqliteAny;
}
use crate::postgres::types::{Float4, Float8, Int2, Int4, Int8, Numeric as PgNumeric};
macro_rules! pg_arith {
($lhs:ty, $rhs:ty => $out:ty) => {
impl ArithmeticOutput<$rhs> for $lhs {
type Output = $out;
}
};
}
pg_arith!(Int2, Int2 => Int2);
pg_arith!(Int2, Int4 => Int4); pg_arith!(Int2, Int8 => Int8); pg_arith!(Int2, Float4 => Float4); pg_arith!(Int2, Float8 => Float8); pg_arith!(Int2, PgNumeric => PgNumeric);
pg_arith!(Int4, Int2 => Int4); pg_arith!(Int4, Int4 => Int4);
pg_arith!(Int4, Int8 => Int8); pg_arith!(Int4, Float4 => Float8); pg_arith!(Int4, Float8 => Float8); pg_arith!(Int4, PgNumeric => PgNumeric);
pg_arith!(Int8, Int2 => Int8); pg_arith!(Int8, Int4 => Int8); pg_arith!(Int8, Int8 => Int8);
pg_arith!(Int8, Float4 => Float8); pg_arith!(Int8, Float8 => Float8); pg_arith!(Int8, PgNumeric => PgNumeric);
pg_arith!(Float4, Int2 => Float4); pg_arith!(Float4, Int4 => Float8); pg_arith!(Float4, Int8 => Float8); pg_arith!(Float4, Float4 => Float4);
pg_arith!(Float4, Float8 => Float8); pg_arith!(Float4, PgNumeric => Float8);
pg_arith!(Float8, Int2 => Float8);
pg_arith!(Float8, Int4 => Float8);
pg_arith!(Float8, Int8 => Float8);
pg_arith!(Float8, Float4 => Float8); pg_arith!(Float8, Float8 => Float8);
pg_arith!(Float8, PgNumeric => Float8);
pg_arith!(PgNumeric, Int2 => PgNumeric);
pg_arith!(PgNumeric, Int4 => PgNumeric);
pg_arith!(PgNumeric, Int8 => PgNumeric);
pg_arith!(PgNumeric, Float4 => Float8); pg_arith!(PgNumeric, Float8 => Float8);
pg_arith!(PgNumeric, PgNumeric => PgNumeric);