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>
impl<T, const N: usize> ExactSlice<T, N>
sourcepub fn from_array(array: &[T; N]) -> &ExactSlice<T, N>
pub fn from_array(array: &[T; N]) -> &ExactSlice<T, N>
Produce a &ExactSlice
from an array of N
T
s.
sourcepub fn from_mut_array(array: &mut [T; N]) -> &mut ExactSlice<T, N>
pub fn from_mut_array(array: &mut [T; N]) -> &mut ExactSlice<T, N>
Produce a &mut ExactSlice
from an array of N
T
s.
sourcepub fn from_slice(slice: &[T]) -> Option<&ExactSlice<T, N>>
pub fn from_slice(slice: &[T]) -> Option<&ExactSlice<T, N>>
Produce an &ExactSlice
from a slice of T
s.
Returns None
if there are not the correct number of elements in slice
.
sourcepub fn from_mut(slice: &mut [T]) -> Option<&mut ExactSlice<T, N>>
pub fn from_mut(slice: &mut [T]) -> Option<&mut ExactSlice<T, N>>
Produce an &mut ExactSlice
from a mutable slice of T
s.
Returns None
if there are not the correct number of elements in slice
.
sourcepub fn as_slice(&self) -> &[T]
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
.
sourcepub fn as_mut_slice(&mut self) -> &mut [T]
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
.
sourcepub fn as_min_slice(&self) -> &MinSlice<T, N>
pub fn as_min_slice(&self) -> &MinSlice<T, N>
Produce a &MinSlice
from this &ExactSlice
. Its tail
will be empty.
sourcepub fn as_mut_min_slice(&mut self) -> &mut MinSlice<T, N>
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.
sourcepub unsafe fn from_slice_unchecked(slice: &[T]) -> &ExactSlice<T, N>
pub unsafe fn from_slice_unchecked(slice: &[T]) -> &ExactSlice<T, N>
Produce an &ExactSlice
from a slice of T
s without checking its length.
§Safety
The caller is responsible for upholding the length invariant
slice.len() == N
, in addition to all normal slice invariants.
sourcepub unsafe fn from_mut_unchecked(slice: &mut [T]) -> &mut ExactSlice<T, N>
pub unsafe fn from_mut_unchecked(slice: &mut [T]) -> &mut ExactSlice<T, N>
Produce an &mut ExactSlice
from a slice of T
s without checking its length.
§Safety
The caller is responsible for upholding the length invariant
slice.len() == N
, in addition to all normal slice invariants.