In Rust by Example's Types chapter, the following example is given for initializing numeric literals:
fn main() {
// Unsuffixed literals, their types depend on how they are used
let i = 1;
let f = 1.0;
}
I am confused by why "their types depend on how they are used". The Book states that "integer types default to i32
" and that floating-point numbers default to f64
. So shouldn't the types of i
and f
already be decided at initialization to be i32
and f64
, respectively? Why would their types depend on anything else?