In writing platform-dependent code, I often find myself wanting infallible conversions such as
u32 -> usize (infallible on 32-bit and 64-bit platforms).
Into impls on the primitive types are only provided for conversions which are infallible on all platforms. How would folks feel about adding platform-dependent conversion traits that are the analogues of the
Into traits, but implemented differently depending on the target platform?
Today, doing platform-dependent conversions like
u32 -> usize usually entails a cast that just happens to be lossless (e.g.,
some_u32_value as usize), possibly combined with a comment explaining why it happens to be lossless. With these traits, we could have the much more robust
usize::from(some_u32_value) and all of the attendant goodness that type safety brings.