Skip to main content

Module array

Module array 

Source
Expand description

This module contains several “hacky” utilities to work around the current lack of generic_const_exprs in Rust.

In several parts of the codebase we have to creates arrays whose length is determined by an associated constant of a trait. Seeing as this is impossible in stable Rust, we instead use the following pattern:

trait MyTrait {
    type Weights: ArrayLike<usize, Elem = f64>;
}

struct MyStruct;

impl MyTrait for MyStruct {
    type Weights = [f64; 10];
}

This module also implements various utilities for serializing arbitrary length arrays. The current version of serde hasn’t been able to do this as it breaks backwards compatibility for zero length arrays.

Modules§

vec
Contains methods for working with vecs of arrays.

Structs§

ArrayWrap
A wrapper around an ArrayLike which implements several common traits depending on the elements of I. This includes Default, Clone, From, and serialization assuming the element type also satisfies those traits.

Traits§

ArrayLike
A helper trait for array types which can be indexed and iterated, with compile time known length. Use of this trait can be removed if generic_const_exprs is ever stabilized.

Functions§

deserialize
Deserialize const generic or arbitrarily-large arrays
serialize