29 releases

0.12.0 Aug 24, 2018
0.11.1 Jun 15, 2018
0.11.0 Mar 22, 2018
0.9.0 Sep 16, 2017
0.0.3 Nov 1, 2015

#10 in Data structures

Download history 15081/week @ 2018-10-21 21037/week @ 2018-10-28 20706/week @ 2018-11-04 22625/week @ 2018-11-11 25870/week @ 2018-11-18 22562/week @ 2018-11-25 25313/week @ 2018-12-02 27725/week @ 2018-12-09 30343/week @ 2018-12-16 31911/week @ 2018-12-23 16774/week @ 2018-12-30 22405/week @ 2019-01-06 29726/week @ 2019-01-13

59,945 downloads per month
Used in 1,204 crates (78 directly)

MIT license

50KB
1K SLoC

Crates.io Build Status

generic-array

This crate implements generic array types for Rust.

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

~132KB