Rust Arithmetic & Type Casting
Links: 105 Rust Index
- Different datatypes cannot be added together
- We cannot add same class different precision values for example
i32
+i64
would give an error. - The result is same type as that of the operands. If the operands are
i8
then the result will also bei8
unless explicitly type casted. - Multiple ways of defining the type of operand
as
is how we do explicit type conversion- In the above example we are going from a smaller to a larger type, if you go to a smaller type from a larger type then an overflow will occur.
Last updated: 2022-05-20