### 2 releases

0.1.1 | May 17, 2022 |
---|---|

0.1.0 | May 17, 2022 |

#**806** in Rust patterns

**MIT/Apache**

10KB

110 lines

# Axmac

Readable indexing macros for 1-4 dimensional data structures.

### The Problem

Have you ever tried to index collections like so:

`let` point3d `=` `[``0.``32``,` `1.``2``,` `10.``7``]``;`
`let` first `=` point3d`[``0``]``;`
`let` next `=` point3d`[``1``]``;`
`//` ...

Trust me, it gets annoying quickly.

The

crate was designed to be a solution to your indexing problems.`axmac`

## Basic Usage

This crate provides the macros

, `ax!`

and `axs!`

which transform
the identifiers `axr!`*x*, *y*, *z* and *w* into

values.`usize`

### ax! (*axis*)

Converts a single identifier into a

value`usize`

`//` Note:
`assert_eq!``(``ax!``(`x`)``,` `0``usize``)``;`
`assert_eq!``(``ax!``(`y`)``,` `1``)``;`
`assert_eq!``(``ax!``(`z`)``,` `2``)``;`
`assert_eq!``(``ax!``(`w`)``,` `3``)``;`
`let` arr `=` `[``"`a`"``,` `"`b`"``,` `"`c`"``,` `"`d`"``]``;`
`assert_eq!``(`arr`[``ax!``(`y`)``]``,` `"`b`"``)``;`
`assert_eq!``(`arr`[``ax!``(`z`)``]``,` `"`c`"``)``;`

### axr! (*axis range*)

Converts a range of identifiers and/or expressions into a range of

's`usize`

`//` Here are just a few of the variations
`let` range1 `=` `axr!``(`x`..``=`z`)``;`
`let` range2 `=` `axr!``(`z`..``4``)``;`
`let` range3 `=` `axr!``(``(``1``)``..`z`)``;`
`assert_eq!``(`range1`,` `0``..``=``3``)``;`
`assert_eq!``(`range2`,` `2``..``4``)``;`
`assert_eq!``(`range3`,` `1``..``2``)``;`
`let` arr `=` `[``"`a`"``,` `"`b`"``,` `"`c`"``,` `"`d`"``]``;`
`assert_eq!``(`arr`[`range1`]``,` `[``"`a`"``,` `"`b`"``,` `"`c`"``]``)``;`
`assert_eq!``(`arr`[`range2`]``,` `[``"`c`"``,` `"`d`"``]``)``;`
`assert_eq!``(`arr`[`range3`]``,` `[``"`b`"``]``)``;`

### axs! (*axes*)

Converts an array of identifiers into an array of

's`usize`

`let` array `=` `axs!``[`x`,` y`,` x`,` w`]``;`
`assert_eq!``(`array`,` `[``0``,` `1``,` `0``,` `3``]``)``;`
`let` array `=` `axs!``[`z`;` `4``]``;`
`assert_eq!``(`array`,` `[``2``,` `2``,` `2``,` `2``]``)``;`

## Contributing

Any suggestions for the codebase, documentation, README (or anything) are more than welcome!

If there are any problems or queries, please submit an issue on our Github page.

## License

This crate is available under the

and/or `MIT`

licenses.`Apache2 .0`