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 98970/week @ 2019-10-13 102175/week @ 2019-10-20 96938/week @ 2019-10-27 102700/week @ 2019-11-03 101472/week @ 2019-11-10 110642/week @ 2019-11-17 99577/week @ 2019-11-24 117754/week @ 2019-12-01 118446/week @ 2019-12-08 109812/week @ 2019-12-15 63258/week @ 2019-12-22 73425/week @ 2019-12-29 114973/week @ 2020-01-05 124920/week @ 2020-01-12 123777/week @ 2020-01-19

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