#generic #array

no-std generic-array

Generic types implementing functionality of arrays

34 releases

new 0.13.1 Jun 24, 2019
0.12.3 Jun 24, 2019
0.12.0 Aug 24, 2018
0.11.1 Jun 15, 2018
0.0.3 Nov 1, 2015

#6 in Data structures

Download history 46941/week @ 2019-03-11 46585/week @ 2019-03-18 45879/week @ 2019-03-25 60123/week @ 2019-04-01 60714/week @ 2019-04-08 52537/week @ 2019-04-15 70946/week @ 2019-04-22 68791/week @ 2019-04-29 54088/week @ 2019-05-06 79189/week @ 2019-05-13 83065/week @ 2019-05-20 92197/week @ 2019-05-27 88082/week @ 2019-06-03 107767/week @ 2019-06-10 75658/week @ 2019-06-17

310,052 downloads per month
Used in 1,961 crates (108 directly)

MIT license

52KB
1.5K SLoC

Crates.io Build Status

generic-array

This crate implements generic array types for Rust.

Requires minumum Rust version of 1.30.1

Documentation

Usage

The Rust arrays [T; N] are problematic in that they can't be used generically with respect to N, so for example this won't work:

struct Foo<N> {
	data: [i32; N]
}

generic-array defines a new trait ArrayLength<T> and a struct GenericArray<T, N: ArrayLength<T>>, which let the above be implemented as:

struct Foo<N: ArrayLength<i32>> {
	data: GenericArray<i32, N>
}

To actually define a type implementing ArrayLength, you can use unsigned integer types defined in typenum crate - for example, GenericArray<T, U5> would work almost like [T; 5] :)

In version 0.1.1 an arr! macro was introduced, allowing for creation of arrays as shown below:

let array = arr![u32; 1, 2, 3];
assert_eq!(array[2], 3);

Dependencies

~129KB