1 unstable release

0.1.2 May 9, 2021
0.1.1 May 8, 2021
0.1.0 May 8, 2021

#669 in Procedural macros

Download history 1754/week @ 2024-07-22 1645/week @ 2024-07-29 1442/week @ 2024-08-05 1440/week @ 2024-08-12 1393/week @ 2024-08-19 1547/week @ 2024-08-26 1677/week @ 2024-09-02 1584/week @ 2024-09-09 1692/week @ 2024-09-16 1669/week @ 2024-09-23 1485/week @ 2024-09-30 1783/week @ 2024-10-07 1752/week @ 2024-10-14 1680/week @ 2024-10-21 1696/week @ 2024-10-28 1547/week @ 2024-11-04

6,843 downloads per month
Used in 15 crates (7 directly)

LGPL-2.0

7KB
102 lines

concat-arrays: a rust macro for concatenating fixed-size arrays

This crate defines concat_arrays!, a macro that allows you to concatenate arrays.

Example:

use concat_arrays::concat_arrays;

fn main() {
    let x = [0];
    let y = [1, 2];
    let z = [3, 4, 5];
    let concatenated = concat_arrays!(x, y, z);
    assert_eq!(concatenated, [0, 1, 2, 3, 4, 5]);
}

Limitations

Due to limitations in rust concat_arrays! can't tell the compiler what the length of the returned array is. As such, the length needs to be inferable from the surrounding context. For example, in the example above the length is inferred by the call to assert_eq!. It is safe to mis-specify the length however since you'll get a compilation error rather than broken code.

Credits

Inspiration for how to implement this was taken largely from the const-concat crate (which implements compile-time array concatenation).

Dependencies

~1.5MB
~37K SLoC