ring/polyfill/
array_flatten.rs

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, a1, a2, a3, a4, a5, a6, a7], [b0, b1, b2, b3, b4, b5, b6, b7]] = 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, a1, a2, a3], [b0, b1, b2, b3], [c0, c1, c2, c3], [d0, d1, d2, d3]] = self;
40        [
41            a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3,
42        ]
43    }
44}