Comment by lynndotpy

Comment by lynndotpy 2 days ago

2 replies

I got into this with Genuary in 2023 or 2024. I found myself wishing Rust had a flag that would automatically coerce between different integer and float types. Just let me put an i32 where you're expected a u64, an f32 where you want an i64, it'll be okay, I swear!

whytevuhuni a day ago

Will it be okay though? i32 to u64 has two ways to convert it:

    i32 -> u32 -> u64
    i32 -> i64 -> u64
This matters with negative numbers, where the first one pads with 32 bits of 0, the second one pads it with 32 bits of 1. Sometimes (as it once happened to me), you wanted the wrong one.
  • lynndotpy a day ago

    Yes, it will be okay because I'm making a pretty picture :) If the default behavior of a conversion surprises me, I'd be able to sus it out and replace it with explicit behavior.

    I'm not saying this is worth adding such a thing to Rust just for this use case, but it would be very nice not to write intos for every number