Macro try_vec_to_array

Source
macro_rules! try_vec_to_array {
    ($vec:ident, $t:ty, $size:expr) => { ... };
}
Expand description

Tries to move a Vec<T> into an array of type T and size N.

§Arguments

  • $vec: The vector to be moved.
  • $t: The type of the elements in the vector and array.
  • $size: The expected size of the array.

§Returns

  • Ok([T; N]) if the vector can be moved successfully.
  • Err(VecToArrayError::SizeMismatch) if the size of the vector doesn’t match the specified size.

§Examples

use vec_to_array::try_vec_to_array;
let v = vec![1, 2, 3];
let arr: [i32; 3] = try_vec_to_array!(v, i32, 3).unwrap();
assert_eq!(arr, [1, 2, 3]);