Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ macro_rules! concat_arrays_size {
}

/// Concatenates provided arrays.
///
/// The macro verifies that the combined length of the input arrays matches the length of the result array.
/// The examples below will fail to compile as the input arrays are either too short or too long.
/// ```compile_fail
/// # #[macro_use] extern crate array_concat;
/// # fn main() {
/// let c: [u32; 6] = concat_arrays!([1, 2, 3], [4, 5]); // too short
/// # }
/// ```
/// ```compile_fail
/// # #[macro_use] extern crate array_concat;
/// # fn main() {
/// let c: [u32; 6] = concat_arrays!([1, 2, 3], [4, 5, 6, 7]); // too long
/// # }
/// ```
#[macro_export]
macro_rules! concat_arrays {
($( $array:expr ),*) => ({
Expand Down Expand Up @@ -39,7 +54,7 @@ macro_rules! concat_arrays {
}

impl<T, A, B, const N: usize> ArrayConcatComposed<T, A, B, N> {
const PANIC: bool = $crate::_const_assert_same_size::<[T; N], Self>();
const PANIC: bool = $crate::_const_assert_same_size::<[T; N], ArrayConcatDecomposed::<T, A, B>>();

#[inline(always)]
const fn have_same_size(&self) -> bool {
Expand Down Expand Up @@ -89,6 +104,21 @@ macro_rules! flatten_split {
}

/// Split the provided array into the specified sizes.
///
/// The macro verifies that the length of the input array matches the combined length of the result arrays.
/// The examples below will fail to compile as the input array is either too short or too long.
/// ```compile_fail
/// # #[macro_use] extern crate array_concat;
/// # fn main() {
/// let (left, right): ([u32; 3], [u32; 4]) = split_array!([1, 2, 3, 4, 5, 6], 3, 4); // too short
/// # }
/// ```
/// ```compile_fail
/// # #[macro_use] extern crate array_concat;
/// # fn main() {
/// let (left, right): ([u32; 3], [u32; 2]) = split_array!([1, 2, 3, 4, 5, 6], 3, 2); // too long
/// # }
/// ```
#[macro_export]
macro_rules! split_array {
($array:expr, $size:expr) => ($array);
Expand Down Expand Up @@ -141,7 +171,7 @@ macro_rules! split_array {
}

impl<T, A, B, const N: usize> ArrayConcatComposed<T, A, B, N> {
const PANIC: bool = $crate::_const_assert_same_size::<[T; N], Self>();
const PANIC: bool = $crate::_const_assert_same_size::<[T; N], ArrayConcatDecomposed::<T, A, B>>();

#[inline(always)]
const fn have_same_size(&self) -> bool {
Expand Down