pub struct NdSlice<'s, T, const N: usize> { /* private fields */ }
Expand description
NdSlice
wraps &[T]
to represent an immutable n-dimensional array
let arr = [1, 2, 3, 4, 5, 6];
let n = NdSlice::new(&arr, [2, 3], Order::RowMajor).unwrap();
assert_eq!(n[[0, 0]], 1);
assert_eq!(n[[1, 2]], 6);
let arr = [1, 2, 3, 4, 5, 6, 7, 8];
let n = NdSlice::new(&arr, [2, 2, 2], Order::RowMajor).unwrap();
assert_eq!(n[[0, 0, 0]], 1);
assert_eq!(n[[1, 1, 1]], 8);
If the slice doesn’t have enough elements to represent an array of that shape, it will
return an Err(ShapeError)
.
let n = NdSlice::new(&[1, 2, 3, 4, 5, 6], [2, 2], Order::RowMajor).unwrap(); // more elements
let n = NdSlice::new(&[1, 2, 3, 4, 5, 6], [2, 4], Order::RowMajor).unwrap(); // less elements
Implementations§
Source§impl<'s, T, const N: usize> NdSlice<'s, T, N>
impl<'s, T, const N: usize> NdSlice<'s, T, N>
Sourcepub fn new(
slice: &'s [T],
shape: [usize; N],
order: Order,
) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
pub fn new( slice: &'s [T], shape: [usize; N], order: Order, ) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
Creates a new NdSlice
with the specified ordering from a given slice and the expected shape
Sourcepub unsafe fn from_ptr(
ptr: *const T,
len: usize,
shape: [usize; N],
order: Order,
) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
pub unsafe fn from_ptr( ptr: *const T, len: usize, shape: [usize; N], order: Order, ) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
Creates a new NdSlice
with the specified ordering from a raw pointer, it’s length and the expected shape
Sourcepub fn new_row_ordered(
slice: &'s [T],
shape: [usize; N],
) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
pub fn new_row_ordered( slice: &'s [T], shape: [usize; N], ) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
Creates a new NdSlice
with row-major ordering from a given slice and the expected shape
Sourcepub unsafe fn row_ordered_from_ptr(
ptr: *const T,
len: usize,
shape: [usize; N],
) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
pub unsafe fn row_ordered_from_ptr( ptr: *const T, len: usize, shape: [usize; N], ) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
Creates a new NdSlice
with row-major ordering from a raw pointer, it’s length and the expected shape
Sourcepub fn col_ordered(
slice: &'s [T],
shape: [usize; N],
) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
pub fn col_ordered( slice: &'s [T], shape: [usize; N], ) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
Creates a new NdSlice
with column-major ordering from a given slice and the expected shape
Sourcepub unsafe fn col_ordered_from_ptr(
ptr: *const T,
len: usize,
shape: [usize; N],
) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
pub unsafe fn col_ordered_from_ptr( ptr: *const T, len: usize, shape: [usize; N], ) -> Result<NdSlice<'s, T, N>, ShapeError<'s, T, N>>
Creates a new NdSlice
with column-major ordering from a raw pointer, it’s length and the expected shape.