Skip to main content

SliceRef

Type Alias SliceRef 

Source
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>
where T: Pod, M: Pod,

Source

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>() * dim for the slice.

Returns an error if:

  • data is not aligned to Self::canonical_align().
  • data.len() != Self::canonical_bytes(dim)`.
Source

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 to Self::canonical_align().
  • data.len() must be equal to Self::canonical_bytes(dim).

This invariant is checked in debug builds and will panic if not satisfied.