When declaring a variable of type vector or a hash map in Rust, we do:
let v: Vec<int>
let m: HashMap<int, int>
To instantiate, we need to call new()
. However, we do so thusly:
Vec::<int>::new()
^^
HashMap::<int, int>::new()
^^
Note the sudden appearance of ::
. Coming from C++, these are odd. Why do these occur? Does having a leading ::
make IDENTIFIER :: < IDENTFIER …
easier to parse than IDENTIFIER < IDENTIFIER
, which might be construed as a less-than operation? (And thus, this is simply a thing to make the language easier to parse? But if so, why not also do it during type specifications, so as to have the two mirror each other?)
(As Shepmaster notes, often Vec::new()
is enough; the type can often be inferred.)