author Dorel Luca <>
Sat, 12 Jan 2019 03:43:46 +0200
changeset 453620 def9811f0311
parent 451894 e6dc0ee80b24
permissions -rw-r--r--
Backed out 2 changesets (bug 1516337) for build bustage. CLOSED TREE Backed out changeset 3c4b8e03e722 (bug 1516337) Backed out changeset 4fc377013db5 (bug 1516337)

[![Build Status](](
# generic-array

This crate implements generic array types for Rust.


## 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);