/rust/registry/src/index.crates.io-1949cf8c6b5b557f/zerovec-0.11.4/src/ule/macros.rs
Line | Count | Source |
1 | | // This file is part of ICU4X. For terms of use, please see the file |
2 | | // called LICENSE at the top level of the ICU4X source tree |
3 | | // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
4 | | |
5 | | /// Given `Self` (`$aligned`), `Self::ULE` (`$unaligned`), and a conversion function (`$single` or |
6 | | /// `Self::from_aligned`), implement `from_array` for arrays of `$aligned` to `$unaligned`. |
7 | | /// |
8 | | /// The `$default` argument is due to current compiler limitations. |
9 | | /// Pass any (cheap to construct) value. |
10 | | #[macro_export] |
11 | | macro_rules! impl_ule_from_array { |
12 | | ($aligned:ty, $unaligned:ty, $default:expr, $single:path) => { |
13 | | #[doc = concat!("Convert an array of `", stringify!($aligned), "` to an array of `", stringify!($unaligned), "`.")] |
14 | 0 | pub const fn from_array<const N: usize>(arr: [$aligned; N]) -> [Self; N] { |
15 | 0 | let mut result = [$default; N]; |
16 | 0 | let mut i = 0; |
17 | | // Won't panic because i < N and arr has length N |
18 | | #[expect(clippy::indexing_slicing)] |
19 | 0 | while i < N { |
20 | 0 | result[i] = $single(arr[i]); |
21 | 0 | i += 1; |
22 | 0 | } |
23 | 0 | result |
24 | 0 | } Unexecuted instantiation: <zerovec::ule::chars::CharULE>::from_array::<_> Unexecuted instantiation: <zerovec::ule::plain::RawBytesULE<2>>::from_array::<_> Unexecuted instantiation: <zerovec::ule::plain::RawBytesULE<4>>::from_array::<_> Unexecuted instantiation: <zerovec::ule::plain::RawBytesULE<8>>::from_array::<_> Unexecuted instantiation: <zerovec::ule::plain::RawBytesULE<16>>::from_array::<_> |
25 | | }; |
26 | | ($aligned:ty, $unaligned:ty, $default:expr) => { |
27 | | impl_ule_from_array!($aligned, $unaligned, $default, Self::from_aligned); |
28 | | }; |
29 | | } |