mbrobbel commented on code in PR #7815: URL: https://github.com/apache/arrow-rs/pull/7815#discussion_r2204671201
########## arrow-cast/src/cast/decimal.rs: ########## @@ -29,7 +33,67 @@ pub(crate) trait DecimalCast: Sized { fn from_f64(n: f64) -> Option<Self>; } +impl DecimalCast for i32 { + fn to_i32(self) -> Option<i32> { + Some(self) + } + + fn to_i64(self) -> Option<i64> { + Some(self as i64) + } + + fn to_i128(self) -> Option<i128> { + Some(self as i128) + } + + fn to_i256(self) -> Option<i256> { + Some(i256::from_i128(self as i128)) + } + + fn from_decimal<T: DecimalCast>(n: T) -> Option<Self> { + n.to_i32() + } + + fn from_f64(n: f64) -> Option<Self> { + n.to_i32() + } +} + +impl DecimalCast for i64 { + fn to_i32(self) -> Option<i32> { + Some(self as i32) Review Comment: The trait docs state that this provides checked conversions. `as` conversions are not checked (it may truncate : https://doc.rust-lang.org/reference/expressions/operator-expr.html#r-expr.as.numeric.int-truncation). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org