pub trait Decimal128Encode {
// Required method
fn try_to_i128_mantissa(&self, target_scale: u32) -> Option<i128>;
}Expand description
Plug-in trait for converting a decimal value into its i128
mantissa rescaled to a target scale.
Implementers MUST use round-half-to-even (banker’s rounding) on
scale-down so the bytes the derive emits match polars’s own
str_to_dec128 path. A None return surfaces as a polars
ComputeError from the generated code.
The codegen invokes this method through UFCS on the selected trait
path, so inherent methods with the same name cannot bypass this
contract. Custom backends (bigdecimal::BigDecimal,
arbitrary-precision types, …) provide their own impls; this crate
ships a rust_decimal::Decimal impl below.
Required Methods§
Sourcefn try_to_i128_mantissa(&self, target_scale: u32) -> Option<i128>
fn try_to_i128_mantissa(&self, target_scale: u32) -> Option<i128>
Returns the mantissa as i128 after rescaling self to
target_scale, or None if the conversion would overflow or
otherwise violate the schema. Implementations MUST round
half-to-even on scale-down.
Implementations on Foreign Types§
Source§impl Decimal128Encode for Decimal
Available on crate feature rust_decimal only.Reference Decimal128Encode impl for rust_decimal::Decimal.
impl Decimal128Encode for Decimal
rust_decimal only.Reference Decimal128Encode impl for rust_decimal::Decimal.
Banker’s-rounding contract: round-half-to-even on scale-down,
checked_mul overflow-to-None on scale-up. This impl is verified
against polars’s str_to_dec128 on a battery of inputs covering
half-tie boundaries (positive and negative), large magnitudes, and
scale-up overflow by this repository’s df-derive-core integration
tests.