Sha256: 9e86d03b400dc818f44df68b76dafd1d89e42a51221bcb0de4259a6529ab6d84

Contents?: true

Size: 1.74 KB

Versions: 38

Compression:

Stored size: 1.74 KB

Contents

[![Crates.io](https://img.shields.io/crates/v/generic-array.svg)](https://crates.io/crates/generic-array)
[![Build Status](https://travis-ci.org/fizyk20/generic-array.svg?branch=master)](https://travis-ci.org/fizyk20/generic-array)
# generic-array

This crate implements generic array types for Rust.

**Requires minumum Rust version of 1.36.0, or 1.41.0 for `From<[T; N]>` implementations**

[Documentation](http://fizyk20.github.io/generic-array/generic_array/)

## 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:

```rust
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:

```rust
struct Foo<N: ArrayLength<i32>> {
	data: GenericArray<i32, N>
}
```

The `ArrayLength<T>` trait is implemented by default for [unsigned integer types](http://fizyk20.github.io/generic-array/typenum/uint/index.html) from [typenum](http://fizyk20.github.io/generic-array/typenum/index.html) crate:

```rust
use generic_array::typenum::U5;

struct Foo<N: ArrayLength<i32>> {
    data: GenericArray<i32, N>
}

fn main() {
    let foo = Foo::<U5>{data: GenericArray::default()};
}
```

For example, `GenericArray<T, U5>` would work almost like `[T; 5]`:

```rust
use generic_array::typenum::U5;

struct Foo<T, N: ArrayLength<T>> {
    data: GenericArray<T, N>
}

fn main() {
    let foo = Foo::<i32, U5>{data: GenericArray::default()};
}
```

In version 0.1.1 an `arr!` macro was introduced, allowing for creation of arrays as shown below:

```rust
let array = arr![u32; 1, 2, 3];
assert_eq!(array[2], 3);
```

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-28.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-27.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-26.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-25.0.2 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-25.0.1 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-25.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-24.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-23.0.2 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-22.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-21.0.1 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-20.0.2 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-20.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-18.0.3 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-17.0.1 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-17.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-16.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-15.0.1 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-15.0.0 ./ext/cargo-vendor/generic-array-0.14.7/README.md
wasmtime-14.0.4 ./ext/cargo-vendor/generic-array-0.14.7/README.md