Crate split_array

Source
Expand description

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>();

Traits§

SplitArray
Split array references in two with compile-time size validation.
SplitArrayRaw
Raw version of SplitArray.
SplitArrayRawMut
Raw mutable version of SplitArray.

Functions§

split_arr
Split an array reference into a reference to the left half and a reference to the right half. The sizes of the halves are validated at compile time.
split_arr_mut
Mutable version of split_arr.
split_arr_raw
Raw version of split_arr.
split_arr_raw_mut
Raw version of split_arr_mut.