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

#4 in Data structures

Download history 73566/week @ 2019-07-27 76421/week @ 2019-08-03 80281/week @ 2019-08-10 76300/week @ 2019-08-17 73848/week @ 2019-08-24 78487/week @ 2019-08-31 79535/week @ 2019-09-07 89295/week @ 2019-09-14 90543/week @ 2019-09-21 96295/week @ 2019-09-28 98783/week @ 2019-10-05 98740/week @ 2019-10-12 103371/week @ 2019-10-19 97392/week @ 2019-10-26 101956/week @ 2019-11-02

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

~135KB