concat-arrays

Crates.ioconcat-arrays
lib.rsconcat-arrays
version0.1.2
sourcesrc
created_at2021-05-08 10:17:53.272795
updated_at2021-05-09 08:34:10.311307
descriptionA macro for concatenating fixed-size arrays
homepage
repositoryhttps://github.com/canndrew/concat-arrays
max_upload_size
id394829
size12,090
Andrew Cann (canndrew)

documentation

https://docs.rs/concat-arrays

README

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).

Commit count: 10

cargo fmt