Some months ago I ran into the same problem in slightly different clothing
// 1st-way
vec![0; len];
// 2nd-way
std::iter::repeat(0).take(len).collect::<Vec<_>>();
As told about in the blog post the first one will be able to be optimized via specializations to a single calloc call. The other here cannot use the same specialization as it does not seem to be able to specialize on the type of iterator yet. This means it will be a malloc followed by a memset when compiled.godbolt: https://godbolt.org/z/8bM7zz4E7
the specific specialization: https://github.com/rust-lang/rust/blob/master/library/alloc/...