Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Rust does not treat integer types as interchangeable.

Rust integers have a type (width and signedness) and you can't combine them without explicitly handling for overflow, etc. Any polymorphism through traits (eg. std::ops::Add) typically only operates over the same type as the source integer.

If types are left unspecified, it's only because type inference knows what type you mean. Since integers are frequently used in structs and function params (places where Rust requires typing), Rust knows the type when you perform operations on these variables. Outside of these cases, Rust will generally require you to disambiguate.

Rust is very deliberate about numerics.



They didn’t say integer types were interchangeable; they said that integer literals have type determined by context, which is correct.


That’s the same as Haskell.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: