32 releases

0.13.0 Apr 14, 2019
0.12.0 Aug 24, 2018
0.11.1 Jun 15, 2018
0.11.0 Mar 22, 2018
0.0.3 Nov 1, 2015

#3 in Data structures

Download history 21764/week @ 2018-12-30 30960/week @ 2019-01-06 32318/week @ 2019-01-13 30813/week @ 2019-01-20 34016/week @ 2019-01-27 38020/week @ 2019-02-03 40742/week @ 2019-02-10 37461/week @ 2019-02-17 42787/week @ 2019-02-24 43515/week @ 2019-03-03 47319/week @ 2019-03-10 46676/week @ 2019-03-17 45048/week @ 2019-03-24 57564/week @ 2019-03-31 63691/week @ 2019-04-07

185,322 downloads per month
Used in 1,570 crates (98 directly)

MIT license

52KB
1K 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