• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H03-May-2022-1,7611,231

tests/H03-May-2022-651507

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D02-Mar-202174 65

.gitignoreH A D06-Feb-2020131 1712

.travis.ymlH A D02-Mar-20211.2 KiB1918

CHANGELOG.mdH A D02-Mar-20212.2 KiB5249

Cargo.tomlH A D02-Mar-20211.2 KiB4136

Cargo.toml.orig-cargoH A D02-Mar-2021801 3222

LICENSEH A D02-Mar-20211.1 KiB2117

README.mdH A D02-Mar-20211.2 KiB3524

rustfmt.tomlH A D02-Mar-202178 43

README.md

1[![Crates.io](https://img.shields.io/crates/v/generic-array.svg)](https://crates.io/crates/generic-array)
2[![Build Status](https://travis-ci.org/fizyk20/generic-array.svg?branch=master)](https://travis-ci.org/fizyk20/generic-array)
3# generic-array
4
5This crate implements generic array types for Rust.
6
7[Documentation](http://fizyk20.github.io/generic-array/generic_array/)
8
9## Usage
10
11The 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:
12
13```rust
14struct Foo<N> {
15	data: [i32; N]
16}
17```
18
19**generic-array** defines a new trait `ArrayLength<T>` and a struct `GenericArray<T, N: ArrayLength<T>>`, which let the above be implemented as:
20
21```rust
22struct Foo<N: ArrayLength<i32>> {
23	data: GenericArray<i32, N>
24}
25```
26
27To actually define a type implementing `ArrayLength`, you can use unsigned integer types defined in [typenum](https://github.com/paholg/typenum) crate - for example, `GenericArray<T, U5>` would work almost like `[T; 5]` :)
28
29In version 0.1.1 an `arr!` macro was introduced, allowing for creation of arrays as shown below:
30
31```rust
32let array = arr![u32; 1, 2, 3];
33assert_eq!(array[2], 3);
34```
35