fn main() {
let a: usize = 100;
let b: u32 = 100;
let z: i32 = a*b;
}
How do I tell the compiler which type I want there?
fn main() {
let a: usize = 100;
let b: u32 = 100;
let z: i32 = a*b;
}
How do I tell the compiler which type I want there?
How do I tell the compiler which type I want there?
You cast the variable to proper type. For example if you want to do the multiplication as i32
type, you would:
let z: i32 = (a as i32) * (b as i32);
More about casting is available in Rust manual - Casting.