Crate const_tools

Crate const_tools 

Source
Expand description

This crate provides macros for destructuring (crate::destructure) and for performing various operations on arrays in const contexts (crate::map, crate::unzip, …).

§Fused Operations

Many operations are fused together in order to generate less code. For example, map! can operate directly on zip!’ed arrays without requiring a separate import:

use const_tools::map;  // `zip!` is built into `map!`

const fn combine<A, B, const N: usize>(a: [A; N], b: [B; N]) -> [(A, B); N] {
    map!(zip!(a, b), |(x, y)| (x, y))
}

Similarly, unzip! can operate directly on the output of map!. You typically only need to import the outermost operation you’re performing.

Macros§

destructure
Allows destructuring in const contexts.
fold
Folds an array into a single value in const contexts.
map
Maps a function over arrays in const contexts.
scan
Produces an array of intermediate fold results in const contexts.
unzip
Unzips an array of tuples into multiple arrays in const contexts.
zip
Zips multiple arrays into an array of tuples in const contexts.