3 ms·
> Are there implicit type conversions? Only implicit refs and derefs I think. > It's a classic problem in language design. If there are no implicit conversion
by masklinn 8y ago
> Are there implicit type conversions?
Only implicit refs and derefs I think.
> It's a classic problem in language design. If there are no implicit conversions, users complain about having to write "1.0" instead of "1", or worse, having to write "1.0L".
Rust handles that by type-inferring literals, the literal itself does not impose a type.
If there are no constraints at all I think it defaults to i32. The type can also be provided explicitly as part of the literal e.g. 1f32 or 7u8.
- chrismorgan 8y agoNote that integer literals and float literals are still distinct; `1` cannot be interpreted as a float, nor can `1.0` be interpreted as an integer—though `1f32` is actually legal (this surprised me; I don’t know when it became legal), while `1.0u32` isn’t.