Turn a Vector Into An Array Of a Given Length
Description
It’s possible to convert [Rust Vectors](Rust Vectors) into arrays of a given length.
Syntax
use std::convert::TryInto;
let v1: Vec
// This will succeed; our vector has a length of three, we’re trying to
// make an array of length three.
let a1: [u32; 3] = v1.try_into().expect(“wrong length”);
// But if we try to do it with a vector of length five…
let v2: Vec
// … this will panic, since we have the wrong length.
let a2: [u32; 3] = v2.try_into().expect(“wrong length”);