32 releases

0.13.2 Jul 8, 2019
0.13.0 Apr 14, 2019
0.12.0 Aug 24, 2018
0.11.1 Jun 15, 2018
0.0.3 Nov 1, 2015

#5 in Data structures

Download history 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 71627/week @ 2019-06-24 66305/week @ 2019-07-01

318,059 downloads per month
Used in 2,256 crates (118 directly)

MIT license

53KB
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

~130KB