I feel Vec::<i32>::new() is not consistent with Vec<i32>
let v = Vec<i32>::new(); // cannot compile
let v1 : Vec<i32> = Vec::new(); // auto inference type parameters
let v2 = Vec::<i32>::new(); // quite weird
The notation is affectionately called the turbofish.
Vec<i32>::new() presents a trade-off when parsing. Is the < introducing the generic argument, or is it a less than operator? To tell the difference requires potentially unbounded look-ahead. The turbofish avoids that.
That is not universally viewed as important. It has been proposed to allow Vec<i32>::new(), but the proposal was abandoned. See here.
That said, specifying the type parameter is less commonly needed than in comparable languages due to type inference as you noted in your second line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With