pub type SliceRef<'a, T, M> = Slice<&'a [T], Ref<'a, M>>;Expand description
A reference to a slice and associated metadata.
Aliased Type§
pub struct SliceRef<'a, T, M> { /* private fields */ }Implementations§
Source§impl<'a, T, M> SliceRef<'a, T, M>
impl<'a, T, M> SliceRef<'a, T, M>
Sourcepub fn from_canonical(data: &'a [u8], dim: usize) -> Result<Self, NotCanonical>
pub fn from_canonical(data: &'a [u8], dim: usize) -> Result<Self, NotCanonical>
Construct an instance of Self viewing data as the canonical layout for a vector.
The canonical layout is as follows:
std::mem::size_of::<T>().max(std::mem::size_of::<M>())for the metadata.- Necessary additional padding to achieve the alignment requirements for
T. std::mem::size_of::<T>() * dimfor the slice.
Returns an error if:
datais not aligned toSelf::canonical_align().data.len() !=Self::canonical_bytes(dim)`.
Sourcepub unsafe fn from_canonical_unchecked(data: &'a [u8], dim: usize) -> Self
pub unsafe fn from_canonical_unchecked(data: &'a [u8], dim: usize) -> Self
Construct a VectorRef from the raw data.
§Safety
data.as_ptr()must be aligned toSelf::canonical_align().data.len()must be equal toSelf::canonical_bytes(dim).
This invariant is checked in debug builds and will panic if not satisfied.