1use super::Numeric;
2
3#[diagnostic::on_unimplemented(
10 message = "arithmetic between `{Self}` and `{Rhs}` is not supported",
11 label = "both operands must be Numeric (Int, BigInt, Float, Double, etc.)"
12)]
13pub trait ArithmeticOutput<Rhs: Numeric = Self>: Numeric {
14 type Output: Numeric;
16}
17
18use crate::sqlite::types::{Integer, Numeric as SqliteNumeric, Real};
26
27impl ArithmeticOutput<Self> for Integer {
29 type Output = Self;
30}
31impl ArithmeticOutput<Real> for Integer {
33 type Output = Real;
34}
35impl ArithmeticOutput<SqliteNumeric> for Integer {
37 type Output = SqliteNumeric;
38}
39
40impl ArithmeticOutput<Integer> for Real {
42 type Output = Self;
43}
44impl ArithmeticOutput<Self> for Real {
46 type Output = Self;
47}
48impl ArithmeticOutput<SqliteNumeric> for Real {
50 type Output = Self;
51}
52
53impl ArithmeticOutput<Integer> for SqliteNumeric {
55 type Output = Self;
56}
57impl ArithmeticOutput<Real> for SqliteNumeric {
59 type Output = Real;
60}
61impl ArithmeticOutput<Self> for SqliteNumeric {
63 type Output = Self;
64}
65
66use crate::sqlite::types::Any as SqliteAny;
68
69impl ArithmeticOutput<Self> for SqliteAny {
70 type Output = Self;
71}
72impl ArithmeticOutput<Integer> for SqliteAny {
73 type Output = Self;
74}
75impl ArithmeticOutput<Real> for SqliteAny {
76 type Output = Self;
77}
78impl ArithmeticOutput<SqliteNumeric> for SqliteAny {
79 type Output = Self;
80}
81impl ArithmeticOutput<SqliteAny> for Integer {
82 type Output = SqliteAny;
83}
84impl ArithmeticOutput<SqliteAny> for Real {
85 type Output = SqliteAny;
86}
87impl ArithmeticOutput<SqliteAny> for SqliteNumeric {
88 type Output = SqliteAny;
89}
90
91use crate::postgres::types::{Float4, Float8, Int2, Int4, Int8, Numeric as PgNumeric};
103
104macro_rules! pg_arith {
107 ($lhs:ty, $rhs:ty => $out:ty) => {
108 impl ArithmeticOutput<$rhs> for $lhs {
109 type Output = $out;
110 }
111 };
112}
113
114pg_arith!(Int2, Int2 => Int2);
116pg_arith!(Int2, Int4 => Int4); pg_arith!(Int2, Int8 => Int8); pg_arith!(Int2, Float4 => Float4); pg_arith!(Int2, Float8 => Float8); pg_arith!(Int2, PgNumeric => PgNumeric);
121
122pg_arith!(Int4, Int2 => Int4); pg_arith!(Int4, Int4 => Int4);
125pg_arith!(Int4, Int8 => Int8); pg_arith!(Int4, Float4 => Float8); pg_arith!(Int4, Float8 => Float8); pg_arith!(Int4, PgNumeric => PgNumeric);
129
130pg_arith!(Int8, Int2 => Int8); pg_arith!(Int8, Int4 => Int8); pg_arith!(Int8, Int8 => Int8);
134pg_arith!(Int8, Float4 => Float8); pg_arith!(Int8, Float8 => Float8); pg_arith!(Int8, PgNumeric => PgNumeric);
137
138pg_arith!(Float4, Int2 => Float4); pg_arith!(Float4, Int4 => Float8); pg_arith!(Float4, Int8 => Float8); pg_arith!(Float4, Float4 => Float4);
143pg_arith!(Float4, Float8 => Float8); pg_arith!(Float4, PgNumeric => Float8);
145
146pg_arith!(Float8, Int2 => Float8);
148pg_arith!(Float8, Int4 => Float8);
149pg_arith!(Float8, Int8 => Float8);
150pg_arith!(Float8, Float4 => Float8); pg_arith!(Float8, Float8 => Float8);
152pg_arith!(Float8, PgNumeric => Float8);
153
154pg_arith!(PgNumeric, Int2 => PgNumeric);
156pg_arith!(PgNumeric, Int4 => PgNumeric);
157pg_arith!(PgNumeric, Int8 => PgNumeric);
158pg_arith!(PgNumeric, Float4 => Float8); pg_arith!(PgNumeric, Float8 => Float8);
160pg_arith!(PgNumeric, PgNumeric => PgNumeric);