![github]![crates-io]![docs-rs]
Build Status

Vec Dimension Shift

This crate is an extension for Vec<T> that extends the dimension-shift features.

Note: vec-dimension-shift crate use an unsafe features in the internal details. As an alternative, dimensionshiftbuffer is available if you want a more flexible runtime dimension shifting or safe-only implementation.

What's the "dimension shift"?

In basically,

Implemented features

  1. VecDimensionShift2D, VecDimensionShift2DFlatten and the 2..16-dimension traits for Vec<T>.
  2. make_vec_dimension_shift_n_dimension! macro for make your desired N-dimension traits.

Note: In the default, 2D, 3D, 4D version of VecDimensionShift?D is enabled. Set default-features=false if you don't need these.

Example

toml [dependencies] vec-dimension-shift = "*"

Example-1

1D -> 2D -> 1D -> 3D -> 1D, and modify an element:

```rust use vecdimensionshift::{ VecDimensionShift2D, VecDimensionShift2DFlatten, VecDimensionShift3D, VecDimensionShift3DFlatten };

fn d2andd3() { let original = vec![0.0, 1.1, 2.2, 3.3, 4.4, 5.5]; dbg!(&original);

let mut d2shifted = original.as2darray().unwrap(); dbg!(&d2shifted); asserteq!(d2shifted[0], [0.0, 1.1]); asserteq!(d2shifted[1], [2.2, 3.3]); asserteq!(d2shifted[2], [4.4, 5.5]); d2_shifted[1][1] = -1.0;

let flatten = d2shifted.asflatten(); dbg!(&flatten);

let mut d3shifted = flatten.as3darray().unwrap(); dbg!(&d3shifted); asserteq!(d3shifted[0], [0.0, 1.1, 2.2]); asserteq!(d3shifted[1], [-1.0, 4.4, 5.5]); d3_shifted[1][1] = -2.0;

let flatten = d3shifted.asflatten(); dbg!(&flatten);

assert_eq!(flatten, vec![0.0, 1.1, 2.2, -1.0, -2.0, 5.5]) } ```

Example-2

  1. Make traits just you needs (eg, 2D and 3D)
  2. -> Make 1D * 12-length buffer
  3. -> Shift the dimension to 2D * 6-length buffer
  4. -> Shift the dimension to ( 2D * 3D ) * 2-length buffer

```rust use vecdimensionshift::makevecdimensionshiftn_dimension;

fn ndimensionmacrogenerator() { makevecdimensionshiftndimension! { VecDimensionShift2D, VecDimensionShift2DFlatten, as2darraynocheck, to2darraynocheck, as2darray, to2darray, as2darraytruncate, to2darraytruncate, as2darraypadding, to2darraypadding, 2 } makevecdimensionshiftndimension! { VecDimensionShift3D, VecDimensionShift3DFlatten, as3darraynocheck, to3darraynocheck, as3darray, to3darray, as3darraytruncate, to3darraytruncate, as3darraypadding, to3darray_padding, 3 }

let original = vec![0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11]; dbg!(&original);

let d2 = original.as2darray().unwrap(); asserteq!(d2[0], [0.0, 1.1]); asserteq!(d2[1], [2.2, 3.3]); asserteq!(d2[2], [4.4, 5.5]); asserteq!(d2[3], [6.6, 7.7]); asserteq!(d2[4], [8.8, 9.9]); asserteq!(d2[5], [10.10, 11.11]); dbg!(&d2);

let d3 = d2.as3darray().unwrap(); asserteq!(d3[0], [[0.0, 1.1], [2.2, 3.3], [4.4, 5.5]]); asserteq!(d3[1], [[6.6, 7.7], [8.8, 9.9], [10.10, 11.11]]); dbg!(&d3); } ```

License

Author