Skip to content

Commit 3e7c887

Browse files
authored
[Variant] Minor: use From impl to make conversion infallable (apache#8068)
# Which issue does this PR close? - Follow on to apache#8044 # Rationale for this change @scovich had a good suggestion here https://github.com/apache/arrow-rs/pull/8044/files#r2257256848: > value.into() makes clear that the conversion is infallible? # What changes are included in this PR? Use `From` impl to make it clear the conversion is infallible and can not lose precision # Are these changes tested? Covered by existing tests # Are there any user-facing changes? No
1 parent c25c5a7 commit 3e7c887

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

parquet-variant/src/variant.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ impl From<u8> for Variant<'_, '_> {
11551155
if let Ok(value) = i8::try_from(value) {
11561156
Variant::Int8(value)
11571157
} else {
1158-
Variant::Int16(value as i16)
1158+
Variant::Int16(i16::from(value))
11591159
}
11601160
}
11611161
}
@@ -1166,7 +1166,7 @@ impl From<u16> for Variant<'_, '_> {
11661166
if let Ok(value) = i16::try_from(value) {
11671167
Variant::Int16(value)
11681168
} else {
1169-
Variant::Int32(value as i32)
1169+
Variant::Int32(i32::from(value))
11701170
}
11711171
}
11721172
}
@@ -1176,7 +1176,7 @@ impl From<u32> for Variant<'_, '_> {
11761176
if let Ok(value) = i32::try_from(value) {
11771177
Variant::Int32(value)
11781178
} else {
1179-
Variant::Int64(value as i64)
1179+
Variant::Int64(i64::from(value))
11801180
}
11811181
}
11821182
}
@@ -1188,7 +1188,7 @@ impl From<u64> for Variant<'_, '_> {
11881188
Variant::Int64(value)
11891189
} else {
11901190
// u64 max is 18446744073709551615, which fits in i128
1191-
Variant::Decimal16(VariantDecimal16::try_new(value as i128, 0).unwrap())
1191+
Variant::Decimal16(VariantDecimal16::try_new(i128::from(value), 0).unwrap())
11921192
}
11931193
}
11941194
}

0 commit comments

Comments
 (0)