Skip to content

Instantly share code, notes, and snippets.

View spikespaz's full-sized avatar
🦀
Science is the scrutiny of magic.

Jacob Birkett spikespaz

🦀
Science is the scrutiny of magic.
View GitHub Profile
@spikespaz
spikespaz / vec_of_array.md
Created January 9, 2022 13:18 — forked from danielhenrymantilla/vec_of_array.md
Vec off arrays (or slices)

The most technically-correct answer to that question: make a Vec of references:

array.iter_mut().collect::<Vec<_>>();

no cloning involved, and you have a Vec.

In practice, however, it's gonna be lifetime-bound (Vec<&mut T> or Vec<&T> if using .iter()). Hence the following more useful answer, but it may involve cloning or other stuff: