Type Inference
Explore how Rust's type inference works with methods and literals. Understand when type annotations are necessary, how the compiler resolves ambiguous integer types, and practice using integer literals to specify types without explicit declarations.
We'll cover the following...
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:
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 ...