Skip to main content

Crate generic_array

Crate generic_array 

👎Deprecated: please upgrade to generic-array 1.x
Expand description

This crate implements a structure that can be used as a generic array type. Core Rust array types [T; N] can’t be used generically with respect to N, so for example this:

struct Foo<T, N> {
    data: [T; N]
}

won’t work.

generic-array exports a GenericArray<T,N> type, which lets the above be implemented as:

use generic_array::{ArrayLength, GenericArray};

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

The ArrayLength<T> trait is implemented by default for unsigned integer types from typenum:

use generic_array::typenum::U5;

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

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

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

use generic_array::typenum::U5;

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

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

For ease of use, an arr! macro is provided - example below:

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

Modules§

arrDeprecated
Implementation for arr! macro.
functionalDeprecated
Functional programming with generic sequences
iterDeprecated
GenericArray iterator implementation.
sequenceDeprecated
Useful traits for manipulating sequences of data stored in GenericArrays
typenum
This crate provides type-level numbers evaluated at compile time. It depends only on libcore.

Macros§

arrDeprecated
Macro allowing for easy generation of Generic Arrays. Example: let test = arr![u32; 1, 2, 3];

Structs§

GenericArrayDeprecated
Struct representing a generic array - GenericArray<T, N> works like [T; N]
GenericArrayIterDeprecated
An iterator that moves out of a GenericArray

Traits§

ArrayLengthDeprecated
Trait making GenericArray work, marking types to be used as length of an array