Last Updated: February 25, 2016
·
116.4K
· pornel

Convert a slice or an array to a Vec in Rust

To create a new vector from a slice:

slice.to_vec();

It works for fixed-size arrays too.

Confusingly, you won't find that method on std::slice documentation page.

All useful slice methods are documented at:

https://doc.rust-lang.org/std/primitive.slice.html