Closed
Description
What it does
Informs the user about a more concise way to create a vector with a known capacity.
I often wrote code like the following:
{
let mut v = vec![];
v.reserve(space_hint);
v
}
since I didn't know about the existence of Vec::with_capacity
, maybe clippy can warn about things like that? It also seems like this can be generalized to cases when we are pushing into an empty vector for a known amount of times.
Advantage
No response
Drawbacks
No response
Example
{
let mut v = vec![];
v.reserve(space_hint);
v
}
Could be written as:
Vec::with_capacity(space_hint)