| Crates.io | vec_to_array |
| lib.rs | vec_to_array |
| version | 0.2.5 |
| created_at | 2023-10-26 15:52:52.86127+00 |
| updated_at | 2024-09-07 21:19:11.926532+00 |
| description | Moves a heap allocated `Vec |
| homepage | |
| repository | https://github.com/mcmah309/vec_to_array |
| max_upload_size | |
| id | 1014674 |
| size | 8,463 |
Moves a heap allocated Vec into a stack allocated array.
let vec: Vec<i64> = vec![1, 2, 3];
let array: [i64; 3] = vec_to_array!(vec, i64, 3);
assert_eq!(array, [1, 2, 3]);
let vec: Vec<i32> = vec![1, 2, 3];
let array: Result<[i32; 3], VecToArrayError> = try_vec_to_array!(vec, i32, 3);
assert_eq!(array.unwrap(), [1, 2, 3]);
Note, 1.48.0 introduced an implementation of try_into for transmuting directly on the heap, which should usually be preferred.