1// Copyright 2023 Brian Smith.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15pub trait ArrayFlatten {
16 type Output;
17
18 /// Returns the flattened form of `a`
19 fn array_flatten(self) -> Self::Output;
20}
21
22impl<T> ArrayFlatten for [[T; 8]; 2] {
23 type Output = [T; 16];
24
25 #[inline(always)]
26 fn array_flatten(self) -> Self::Output {
27 let [[a0: T, a1: T, a2: T, a3: T, a4: T, a5: T, a6: T, a7: T], [b0: T, b1: T, b2: T, b3: T, b4: T, b5: T, b6: T, b7: T]] = self;
28 [
29 a0, a1, a2, a3, a4, a5, a6, a7, b0, b1, b2, b3, b4, b5, b6, b7,
30 ]
31 }
32}
33
34impl<T> ArrayFlatten for [[T; 4]; 4] {
35 type Output = [T; 16];
36
37 #[inline(always)]
38 fn array_flatten(self) -> Self::Output {
39 let [[a0: T, a1: T, a2: T, a3: T], [b0: T, b1: T, b2: T, b3: T], [c0: T, c1: T, c2: T, c3: T], [d0: T, d1: T, d2: T, d3: T]] = self;
40 [
41 a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3,
42 ]
43 }
44}
45