#generic #array

generic-array

Generic types implementing functionality of arrays

28 releases

0.11.1 Jun 15, 2018
0.11.0 Mar 22, 2018
0.10.0 Feb 21, 2018
0.9.0 Sep 16, 2017
0.0.3 Nov 1, 2015

#6 in Data structures

Download history 7685/week @ 2018-05-06 11276/week @ 2018-05-13 12280/week @ 2018-05-20 13755/week @ 2018-05-27 11397/week @ 2018-06-03 15775/week @ 2018-06-10 13472/week @ 2018-06-17 16481/week @ 2018-06-24 14499/week @ 2018-07-01 11425/week @ 2018-07-08 15172/week @ 2018-07-15 16482/week @ 2018-07-22 12630/week @ 2018-07-29

42,992 downloads per month

Crates.io Build Status

generic-array

This crate implements generic array types for Rust.

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);
MIT license

Dependencies

Reverse deps