3 ms·
There are a couple of options: - Repeating the vector using the built-in method `Vec::repeat`. This allocates a new vector, but `reserve` is likely to do the s
by paavohtl 5y ago
There are a couple of options:
- Repeating the vector using the built-in method `Vec::repeat`. This allocates a new vector, but `reserve` is likely to do the same, just implicitly.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=49879aad21685ffa2d3c89b0a8e7145b https://play.rust-lang.org/?version=stable&mode=debug&editio...
- Using a traditional for loop. There are no lifetime issues, because a new reference is acquired on each iteration. The reserve is not required, but I included it to match your C++ version. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=30c4f5e4063dc797af04dbff3976c190 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- Creating an array of slices and then concatenating them into a new Vec using the concat method on slices: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2a11a101cb43daa640b56fc36417bcd1 https://play.rust-lang.org/?version=stable&mode=debug&editio...