Type Inference

We'll cover the following...

When we use a let to declare a new variable, we have the option to give it a type. In other words, both of the lets below are valid Rust:

Press + to interact
fn main() {
let x: i32 = 5;
let x = 5;
println!("x == {}", x);
}

We call the : i32 a type annotation, and so far it’s been entirely optional. This is because Rust does something called type inference: it infers, or figures out, the type for any expression. This is pretty easy with a string literal or a Boolean literal. They must be of type ...