Crates.io | split_array |
lib.rs | split_array |
version | 0.2.0 |
source | src |
created_at | 2024-04-08 01:05:08.124215 |
updated_at | 2024-04-12 22:57:28.766124 |
description | Split array references in two with compile-time size validation. |
homepage | |
repository | |
max_upload_size | |
id | 1199671 |
size | 16,274 |
Split array references in two with compile-time size validation.
Unstable features used:
The sizes of the two halves can usually be inferred:
use split_array::SplitArray;
let mut array: [usize; 5] = [0, 1, 2, 3, 4];
let (left, right) = array.split_arr_mut();
* left = [10, 11, 12];
* right = [23, 24];
assert_eq!([10, 11, 12, 23, 24], array);
They can be annotated explicitly as well:
use split_array::SplitArray;
let array: [usize; 5] = [0, 1, 2, 3, 4];
let (left, right) = array.split_arr::<2 > ();
assert_eq!([0, 1, 2], *left);
assert_eq!([3, 4], *right);
The annotated size is validated at compile-time. This won't compile:
use split_array::SplitArray;
let array: [usize; 5] = [0, 1, 2, 3, 4];
let (left, right) = array.split_arr::<6 > ();