Struct NdSliceMut

Source
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>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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.

Trait Implementations§

Source§

impl<'s, T: Debug, const N: usize> Debug for NdSliceMut<'s, T, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const N: usize> Index<[usize; N]> for NdSliceMut<'_, T, N>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: [usize; N]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const N: usize> IndexMut<[usize; N]> for NdSliceMut<'_, T, N>

Source§

fn index_mut(&mut self, index: [usize; N]) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<'s, T, const N: usize> Freeze for NdSliceMut<'s, T, N>

§

impl<'s, T, const N: usize> RefUnwindSafe for NdSliceMut<'s, T, N>
where T: RefUnwindSafe,

§

impl<'s, T, const N: usize> Send for NdSliceMut<'s, T, N>
where T: Send,

§

impl<'s, T, const N: usize> Sync for NdSliceMut<'s, T, N>
where T: Sync,

§

impl<'s, T, const N: usize> Unpin for NdSliceMut<'s, T, N>

§

impl<'s, T, const N: usize> !UnwindSafe for NdSliceMut<'s, T, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.