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