konst/
array.rs

1//! Const equivalents of array functions.
2
3/// Const equivalent of
4/// [`array::map`](https://doc.rust-lang.org/std/primitive.array.html#method.map).
5///
6/// **Limitation:** requires `$array` and the elements
7/// returned by the passed-in function to be `Copy`.
8///
9/// # Example
10///
11/// ```rust
12/// use konst::array;
13///
14/// const TRIMMED: [&str; 3] = array::map!(["  foo", "bar  ", "  baz  "], konst::string::trim);
15/// assert_eq!(TRIMMED, ["foo", "bar", "baz"]);
16///
17/// const LENGTHS: [usize; 3] = array::map!(["foo", "hello", "bar baz"], |s| s.len());
18/// assert_eq!(LENGTHS, [3, 5, 7]);
19///
20/// const SQUARED: [u32; 6] = array::map!([1, 2, 3, 4, 5, 6], |x: u32| x.pow(2));
21/// assert_eq!(SQUARED, [1, 4, 9, 16, 25, 36]);
22///
23/// ```
24///
25#[cfg(feature = "rust_1_56")]
26#[cfg_attr(feature = "docsrs", doc(cfg(feature = "rust_1_56")))]
27pub use konst_macro_rules::array_map as map;