pub trait ArithmeticOutput<Rhs: Numeric = Self, Op = ArithmeticOp>: Numeric {
type Output: Numeric;
type Nullability: ArithmeticNullability;
}Expand description
The SQL type produced by Self <op> Rhs, where both sides are Numeric.
The output follows each database’s promotion rules:
- SQLite:
Integer op IntegerisInteger; anyRealmakes itReal;NumericwithIntegerstaysNumeric;Anywith anything isAny. - PostgreSQL: integers widen to the wider integer (
Int2 + Int8isInt8); an integer with a float gives a float (Int4 + Float8isFloat8; onlyInt2withFloat4staysFloat4);Numericwith an integer staysNumeric;Numericwith a float givesFloat8. - MySQL: integer
+,-and*giveBigInt(BigIntUnsignedif an operand is unsigned); integer%givesBigIntorBigIntUnsignedfollowing the left operand;/of exact values givesDecimal;Decimalwith an integer givesDecimal; anyFloatorDoubleoperand givesDouble.Yearcounts as an unsigned integer.
Op selects the operator (AddOp, SubOp, MulOp, DivOp, RemOp).
The default, ArithmeticOp, is an operator-independent form implemented
only for SQLite and PostgreSQL, whose result type does not depend on the
operator.
§Examples
use drizzle_types::{ArithmeticOutput, Numeric};
use drizzle_types::postgres::types::{Float8, Int2, Int4, Int8};
fn output<L, R, O>()
where
L: ArithmeticOutput<R, Output = O>,
R: Numeric,
O: Numeric,
{
}
output::<Int2, Int8, Int8>(); // smallint + bigint -> bigint
output::<Int4, Float8, Float8>(); // integer + double -> doubleRequired Associated Types§
Sourcetype Nullability: ArithmeticNullability
type Nullability: ArithmeticNullability
Whether the operator itself can produce NULL even from non-NULL
operands: / and % on SQLite’s Integer, Real and Numeric and
on every MySQL numeric type, which return NULL for a zero divisor.
PostgreSQL raises an error instead, so its operators only propagate
operand nullability.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".