3 unstable releases
0.2.0 | Apr 12, 2024 |
---|---|
0.1.1 | Apr 8, 2024 |
0.1.0 | Apr 8, 2024 |
#328 in No standard library
101 downloads per month
16KB
302 lines
split_array
Split array references in two with compile-time size validation.
This crate requires nightly!
Unstable features used:
Examples
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 > ();
lib.rs
:
Split array references in two with compile-time size validation.
Examples
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>();