4 stable releases
1.1.1 | Aug 7, 2023 |
---|---|
1.1.0 | Aug 6, 2023 |
1.0.1 | Aug 6, 2023 |
#2527 in Rust patterns
Used in barbarosa
11KB
214 lines
cartesian-array-product
This crate provides a macro to generate an array with the cartesian product of multiple arrays.
It is meant to be usable in const
contexts.
Usage
Add this crate as a dependency:
cargo add cartesian_array_product
Example
use cartesian_array_product::cartesian_array;
let product = cartesian_array!([1, 2], [3, 4]);
let expected = [
(1, 3),
(2, 3),
(1, 4),
(2, 4),
];
assert_eq!(product, expected);
See https://docs.rs/cartesian_array_product for further info.
Caveat
This macro doesn't allow trailing commas in the input arrays. This is because $($var:whatever),*
doesn't match trailing commas, and adding manually $($var:whatever),* $(,)?
is too much repetation for a thing that, honestly, isn't that important. (maybe i'm just writing this to convience myself because i hate not having trailing commas 😭😭😭)
Dependencies
~4KB