rustls_rustcrypto/
misc.rs1#[macro_export]
2macro_rules! const_concat_slices {
3 ($ty:ty, $a:expr, $b:expr $(,)*) => {{
4 const A: &[$ty] = $a;
5 const B: &[$ty] = $b;
6 const __LEN: usize = A.len() + B.len();
7 const __CONCATENATED: &[$ty; __LEN] = &{
8 let mut out: [$ty; __LEN] = if __LEN == 0 {
9 unsafe { core::mem::transmute([0u8; core::mem::size_of::<$ty>() * __LEN]) }
10 } else if A.len() == 0 {
11 [B[0]; __LEN]
12 } else {
13 [A[0]; __LEN]
14 };
15 let mut i = 0;
16 while i < A.len() {
17 out[i] = A[i];
18 i += 1;
19 }
20 i = 0;
21 while i < B.len() {
22 out[i + A.len()] = B[i];
23 i += 1;
24 }
25 out
26 };
27
28 __CONCATENATED
29 }};
30 ($ty:ty, $a:expr, $b:expr, $($c:expr), + $(,)* ) => {{
31 const CON: &[$ty] = const_concat_slices!($ty, $a, $b);
32 const_concat_slices!($ty, CON, $($c), +)
33 }}
34}
35
36pub(crate) use const_concat_slices;