#array #generic #extension

array_ext

Extra functionality for Rust arrays

4 releases (breaking)

Uses new Rust 2021

0.4.0 Nov 11, 2022
0.3.0 Jun 11, 2020
0.2.0 Nov 1, 2016
0.1.0 Oct 21, 2016

#24 in #extension

Download history 14/week @ 2022-08-12 13/week @ 2022-08-19 7/week @ 2022-08-26 15/week @ 2022-09-02 27/week @ 2022-09-09 11/week @ 2022-09-16 5/week @ 2022-09-23 21/week @ 2022-09-30 17/week @ 2022-10-07 3/week @ 2022-10-14 9/week @ 2022-10-21 19/week @ 2022-10-28 28/week @ 2022-11-04 40/week @ 2022-11-11 15/week @ 2022-11-18 8/week @ 2022-11-25

94 downloads per month
Used in vulkan-malloc

MIT license

15KB
380 lines

array_ext

Extra functionality for Rust arrays.

Documentation

Examples

The trait Array provides fixed-size array generics:

use array_ext::Array;

fn average<T: Array<f32>>(arr: T) -> f32
{
    let n = arr.len() as f32;
    arr.foldl(0.0, |acc, val| acc + val) / n
}

assert!((average([8.96, 3.14, 17.9]) - 10.0).abs() < f32::EPSILON);

Some methods, like zip_with, are provided by the sized ArrayN trait that allows doing full [T; N] -> [U; N] mapping. The base Array trait can only do [T; N] -> [T; N] mapping.

This was originally made as workaround for the lack of const generics, but since v0.4 everything is implemented using const generics.


lib.rs:

Extra functionality for Rust arrays.

No runtime deps

Features

  • nightly