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

#3 in Data structures

Download history 72088/week @ 2019-06-26 40717/week @ 2019-07-03 40425/week @ 2019-07-10 66019/week @ 2019-07-17 72522/week @ 2019-07-24 72349/week @ 2019-07-31 79204/week @ 2019-08-07 79758/week @ 2019-08-14 74510/week @ 2019-08-21 73063/week @ 2019-08-28 83420/week @ 2019-09-04 82306/week @ 2019-09-11 88499/week @ 2019-09-18 95026/week @ 2019-09-25 100017/week @ 2019-10-02

318,059 downloads per month
Used in 2,535 crates (124 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