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

#6 in Data structures

Download history 98344/week @ 2019-11-01 100943/week @ 2019-11-08 106284/week @ 2019-11-15 109842/week @ 2019-11-22 107638/week @ 2019-11-29 120729/week @ 2019-12-06 110646/week @ 2019-12-13 71544/week @ 2019-12-20 69977/week @ 2019-12-27 106100/week @ 2020-01-03 128953/week @ 2020-01-10 124780/week @ 2020-01-17 120631/week @ 2020-01-24 120992/week @ 2020-01-31 111547/week @ 2020-02-07

443,327 downloads per month
Used in 3,206 crates (139 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

~205KB