Avatar ·

Creating a vector of zeros of a given size in Rust

Hello everyone! I just started learning Rust and encountered this problem. I need to create a vector (Vec) of a certain size filled with zeros. In other languages, for example in Python, I just write `[0] * n`, and in C++ — `std::vector v(n, 0)`. But in Rust I can't find a direct equivalent.\n\nI tried several options, but they don't work or give compilation errors. For example:\n\n```rust\nlet v = vec![0; 5]; // This works for Copy types, but I need it for f64\nlet v2: Vec = vec![0; 5]; // Error: expected f64, found integer\n```\n\nI also tried to create a vector using `Vec::with_capacity(5)` and then fill it in a loop, but that seems too verbose. Is there a more elegant way, like in other languages? I need to create a vector of 1000 elements of type `f64`, all