maparr
(help with array based maps) 📙A rust macro to build a static Map
based on const array.
The idea is that you define your map first, and then you can use it wheather nessary.
```rust use maparr::maparr;
maparr!( Continents; ASIA, AFRICA, AMERICANORTH, AMERICASOUTH, ANTARCTICA, EUROPE, AUSTRALIA, );
const CONTINENTSQUAREMILES: Continents
fn main() { for (sqmiles, continent) in CONTINENTSQUAREMILES.intoiter().zip(Continents::names()) { println!("{continent:15} = {sq_miles:10} (sq mi)"); } } ```
You shall expect to get the following output in stdout
.
text
ASIA = 17212000 (sq mi)
AFRICA = 11608000 (sq mi)
AMERICA_NORTH = 9365000 (sq mi)
AMERICA_SOUTH = 6880000 (sq mi)
ANTARCTICA = 5100000 (sq mi)
EUROPE = 3837000 (sq mi)
AUSTRALIA = 2968000 (sq mi)
You can modify the built map (even in const
context if allowed).
```rust use maparr::maparr;
maparr!(
Continents
fn main() { let mut continents = maparr!( Continents; ASIA = 17212000, AFRICA = 11608000, AMERICANORTH = 9365000, AMERICASOUTH = 6880000, ANTARCTICA = 5100000, EUROPE = 3837000, AUSTRALIA = 2968000, );
continents.set(Continents::ASIA, 17_212_001);
assert_eq!(continents[Continents::ASIA], 17_212_001);
continents = continents.map(|value| value * 2);
assert_eq!(continents[Continents::ASIA], 17_212_001 * 2);
} ```