Crate multiarray

Source
Expand description

This crate provides types to deal with multi-dimensional data. It basically tries to generalize over Box<[T]>, &[T] and &mut [T] to multiple dimensions. As a side effect, it also supports one-dimensional arrays that have a stride other than one.

§Examples

Here’s an example of a 3D array. One 2D view and one 1D view into part of the data is created.

use multiarray::*;

let mut voxels = Array3D::new([3,4,5], 0); // 3x4x5 ints
voxels[[0,0,0]] = 1;
voxels[[1,2,3]] = 23;
voxels[[2,3,4]] = 42;
assert!(voxels[[1,2,3]] == 23);
let slice = voxels.eliminated_dim(1, 2);   // 2D slice
assert!(slice[[1,3]] == 23);
let lane = slice.eliminated_dim(1, 3);     // 1D lane
assert!(lane[1] == 23);

Please note that [usize; N] is used as index. For convenience the one-dimensional case also supports usize as index in addition to [usize; 1], the one-dimensional views are convertible from borrowed slices (&[T] and &mut[T]) via std::convert::{ From, Into } and also implement the iterator traits Iterator, ExactSizeIterator and DoubleEndedIterator.

Structs§

Dim1
Dim2
Dim3
Dim4
Dim5
Dim6
MultiArray
Type for multi-dimensional arrays that are organized linearly in memory much like a C array but with dynamically determined sizes.
MultiArrayRef
Shared view of a multi-dimensional array
MultiArrayRefMut
Mutable view of a multi-dimensional array
Wrapped
Helper type to wrap things. This helps avoiding trait coherency issues w.r.t. AsRef and From.

Traits§

LayoutHelper
Helper trait for creating small isize and usize arrays of a fixed size. They are used to store information about the memory layout of a multi-dimensional array.
LayoutHelperExt
Extension trait for dimensions higher than one

Type Aliases§

Array1D
Type alias for a 1D array
Array1DRef
Shared view of a 1D array
Array1DRefMut
Mutable view of a 1D array
Array2D
Type alias for a 2D array
Array2DRef
Shared view of a 2D array
Array2DRefMut
Mutable view of a 2D array
Array3D
Type alias for a 3D array
Array3DRef
Shared view of a 3D array
Array3DRefMut
Mutable view of a 3D array
Array4D
Type alias for a 4D array
Array4DRef
Shared view of a 4D array
Array4DRefMut
Mutable view of a 4D array
Array5D
Type alias for a 5D array
Array5DRef
Shared view of a 5D array
Array5DRefMut
Mutable view of a 5D array
Array6D
Type alias for a 6D array
Array6DRef
Shared view of a 6D array
Array6DRefMut
Mutable view of a 6D array