scovich commented on code in PR #8044: URL: https://github.com/apache/arrow-rs/pull/8044#discussion_r2257256848
########## parquet-variant/src/variant.rs: ########## @@ -1149,6 +1149,50 @@ impl From<i64> for Variant<'_, '_> { } } +impl From<u8> for Variant<'_, '_> { + fn from(value: u8) -> Self { + // if it fits in i8, use that, otherwise use i16 + if let Ok(value) = i8::try_from(value) { + Variant::Int8(value) + } else { + Variant::Int16(value as i16) Review Comment: `value.into()` makes clear that the conversion is infallible? (more below) ########## parquet-variant/src/variant.rs: ########## @@ -1149,6 +1149,50 @@ impl From<i64> for Variant<'_, '_> { } } +impl From<u8> for Variant<'_, '_> { + fn from(value: u8) -> Self { + // if it fits in i8, use that, otherwise use i16 + if let Ok(value) = i8::try_from(value) { + Variant::Int8(value) + } else { + Variant::Int16(value as i16) + } + } +} + +impl From<u16> for Variant<'_, '_> { + fn from(value: u16) -> Self { + // if it fits in i16, use that, otherwise use i32 + if let Ok(value) = i16::try_from(value) { + Variant::Int16(value) + } else { + Variant::Int32(value as i32) + } + } Review Comment: Could also consider doing: ```rust i16::try_from(value).map_or_else(|| Variant::Int32(value.into()), Variant::Int16) ``` tho it's a bit up in the air whether the compactness/readability trade-off is a net win -- 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