Suggestion: allow `vec![T]`

I am not sure if feasible altogether, but in my opinion it would be convenient to define an empty Vec as follows:

let v = vec![T];

instead of:

let v: Vec<T> = vec![];

or:

let v: Vec<T> = Vec::new();

The syntax currently is:

let v = Vec::<T>::new();

4 Likes

I doubt this is possible.

struct x {}
let x = 0i32;
let v = vec![x]; // what is v?
6 Likes

Also, you usually don’t need to specify the type, as it will be inferred.

2 Likes

Besides, it’s not at all intuitive to the reader without an explanation what a type inside a macro is when said macro usually takes values, not types.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.