Vec<&T> to Vec<T>


#1

How to get Vec, where have Vec<&T>?


#2

There’s no easy way, because &T means it’s borrowed, and T means it’s owned, and you can’t take ownership of a thing you’ve borrowed — Rust doesn’t support stealing! :wink:

The types are also physically laid out differently in memory, so there isn’t even a way to cheat it. You’ll have to copy all elements:

vec.into_iter().cloned().collect()

TWiR quote of the week
#3

Cool! Thanks!