pub struct UnalignedSlice<'a, T> { /* private fields */ }Expand description
A minimally functional span over a potentially unaligned slice of elements of type T.
Like &[T], this type guarantees that the memory
[self.as_ptr(), self.as_ptr().add(self.len())) is valid for reads.
However, unlike &[T], the pointer Self::as_ptr is not guaranteed to be aligned
to std::mem::align_of::<T>().
If the type T is Copy, then std::ptr::read_unaligned can be used on the valid
memory region for this slice to access values of type T.
Implementations§
Source§impl<'a, T> UnalignedSlice<'a, T>
impl<'a, T> UnalignedSlice<'a, T>
Sourcepub const unsafe fn new(ptr: *const T, len: usize) -> Self
pub const unsafe fn new(ptr: *const T, len: usize) -> Self
Construct a new UnalignedSlice over the region [ptr, ptr.add(len)).
§Safety
The provided memory region must be valid for reading via std::ptr::read_unaligned
for the duration of the associated lifetime.
Note that ptr need not be aligned to std::mem::align_of::<T>().
Argument ptr may be null if len == 0.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Return the number of elements of type T available for reading from Self::as_ptr.
Trait Implementations§
Source§impl<T> AsUnaligned for UnalignedSlice<'_, T>
impl<T> AsUnaligned for UnalignedSlice<'_, T>
Source§fn as_unaligned(&self) -> UnalignedSlice<'_, T>
fn as_unaligned(&self) -> UnalignedSlice<'_, T>
UnalignedSlice view of self.