Skip to main content

integer_to_decimal_native

Function integer_to_decimal_native 

Source
fn integer_to_decimal_native<I, M>(value: I) -> Option<M>
where I: Into<i128>, M: DecimalCast,
Expand description

Convert an integer to a decimal native value without wrapping.

AsPrimitive / as silently truncates when the source is wider than M (for example 5_000_000_000i64 as i32). All integer sources fit in i128 losslessly, which DecimalCast then converts to the decimal native type with a range check. For types that always fit (e.g. i64 to Decimal128) this should get optimized to being equivalent to i64 as i128.