const_tools/lib.rs
1//! This crate provides macros for destructuring ([`crate::destructure`]) and for performing various operations on arrays in const contexts ([`crate::map`], [`crate::unzip`], ...).
2//!
3//! ## Fused Operations
4//!
5//! Many operations are fused together in order to generate less code.
6//! For example, [`map!`] can operate directly on [`zip!`]'ed arrays without requiring a separate import:
7//!
8//! ```
9//! use const_tools::map; // `zip!` is built into `map!`
10//!
11//! const fn combine<A, B, const N: usize>(a: [A; N], b: [B; N]) -> [(A, B); N] {
12//! map!(zip!(a, b), |(x, y)| (x, y))
13//! }
14//! ```
15//!
16//! Similarly, [`unzip!`] can operate directly on the output of [`map!`].
17//! You typically only need to import the outermost operation you're performing.
18#![no_std]
19
20#[doc(hidden)]
21pub mod __call;
22
23#[doc(hidden)]
24pub mod __manually_drop_inner_ref;
25pub use __manually_drop_inner_ref::*;
26
27#[doc(hidden)]
28pub mod __maybe_uninit_array_assume_init;
29pub use __maybe_uninit_array_assume_init::*;
30
31#[doc(hidden)]
32pub mod __maybe_uninit_array_uninit;
33pub use __maybe_uninit_array_uninit::*;
34
35#[doc(hidden)]
36pub mod __same_len;
37pub use __same_len::*;
38
39#[doc(hidden)]
40pub mod __zip_left;
41
42#[doc(hidden)]
43pub mod destructure;
44pub use destructure::*;
45
46#[doc(hidden)]
47mod fold;
48
49#[doc(hidden)]
50mod map;
51
52#[doc(hidden)]
53mod scan;
54
55#[doc(hidden)]
56mod unzip;
57
58#[doc(hidden)]
59mod zip;
60
61// The array-related macros implemented by this library use the following (meta)variable naming scheme:
62//
63// $(i|o)(i|a)(|e|p)
64// - (i|o) -> input or output
65// - (i|a) -> item or array
66// - (|e|p) -> ident, expression, or pattern
67//
68// As an example, `$iae:expr` would be an expression for the input array, or multiple in case of a repetition.