Struct nslice::ExactSlice

source ·
pub struct ExactSlice<T, const N: usize> { /* private fields */ }
Expand description

A reference to a region of memory which contains exactly N elements of type T.

ExactSlice is merely a way of reinterpreting an existing slice (&[T] or &mut [T]), but because there is no need to store a length for retrieval at runtime, its representation consists of just one pointer.

Implementations§

source§

impl<T, const N: usize> ExactSlice<T, N>

source

pub fn from_array(array: &[T; N]) -> &ExactSlice<T, N>

Produce a &ExactSlice from an array of N Ts.

source

pub fn from_mut_array(array: &mut [T; N]) -> &mut ExactSlice<T, N>

Produce a &mut ExactSlice from an array of N Ts.

source

pub fn from_slice(slice: &[T]) -> Option<&ExactSlice<T, N>>

Produce an &ExactSlice from a slice of Ts. Returns None if there are not the correct number of elements in slice.

source

pub fn from_mut(slice: &mut [T]) -> Option<&mut ExactSlice<T, N>>

Produce an &mut ExactSlice from a mutable slice of Ts. Returns None if there are not the correct number of elements in slice.

source

pub fn as_slice(&self) -> &[T]

Returns a slice over the memory referred to by the ExactSlice. Its length is guaranteed to be exactly N.

source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice over the memory referred to by the ExactSlice. Its length is guaranteed to be exactly N.

source

pub fn as_min_slice(&self) -> &MinSlice<T, N>

Produce a &MinSlice from this &ExactSlice. Its tail will be empty.

source

pub fn as_mut_min_slice(&mut self) -> &mut MinSlice<T, N>

Produce a &mut MinSlice from this &min ExactSlice. Its tail will be empty.

source

pub unsafe fn from_slice_unchecked(slice: &[T]) -> &ExactSlice<T, N>

Produce an &ExactSlice from a slice of Ts without checking its length.

§Safety

The caller is responsible for upholding the length invariant slice.len() == N, in addition to all normal slice invariants.

source

pub unsafe fn from_mut_unchecked(slice: &mut [T]) -> &mut ExactSlice<T, N>

Produce an &mut ExactSlice from a slice of Ts without checking its length.

§Safety

The caller is responsible for upholding the length invariant slice.len() == N, in addition to all normal slice invariants.

Trait Implementations§

source§

impl<'a, T, const N: usize> Into<&'a ExactSlice<T, N>> for &'a MinSlice<T, N>

source§

fn into(self) -> &'a ExactSlice<T, N>

Converts this type into the (usually inferred) input type.
source§

impl<'a, T, const N: usize> Into<&'a MinSlice<T, N>> for &'a ExactSlice<T, N>

source§

fn into(self) -> &'a MinSlice<T, N>

Converts this type into the (usually inferred) input type.
source§

impl<'a, T, const N: usize> Into<&'a mut ExactSlice<T, N>> for &'a mut MinSlice<T, N>

source§

fn into(self) -> &'a mut ExactSlice<T, N>

Converts this type into the (usually inferred) input type.
source§

impl<'a, T, const N: usize> Into<&'a mut MinSlice<T, N>> for &'a mut ExactSlice<T, N>

source§

fn into(self) -> &'a mut MinSlice<T, N>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for ExactSlice<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for ExactSlice<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for ExactSlice<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for ExactSlice<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for ExactSlice<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for ExactSlice<T, N>
where T: UnwindSafe,

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

§

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

§

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.