Type inference lets the Rust compiler determine local variable types from program context, so most variables need no explicit annotations. Function inputs and outputs still require annotations, and inferred types remain statically checked. section 1.4.3
Infer a map’s types from its contents
Rust can infer the map and vector types from the inserted values: `let mut map = HashMap::new(); map.insert(1, vec![4, 10]);`. The equivalent explicit form is `let mut map: HashMap<i32, Vec<i32>> = HashMap::new();`; both express the same structure, but the annotations are usually optional. section 1.4.3
Infer a variable from its initializer
A variable initialized with `let` receives its type from the value on the right-hand side. For example, an artwork value is inferred as the declared `Artwork` struct, while `.to_string()` produces the required `String` field value. section 2.1
Listing 1.3 Initializing a map of numbers to lists of numbers in Java 1.6
HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>(); ArrayList<Integer> list = new ArrayList<Integer>(); list.add(4); list.add(10); map.put(1, list);
Compare the verbose Java 1.6 map declaration with the shorter Rust initialization, then inspect the optional explicit Rust annotation. section 1.4.3















