pub struct StridedSlice<T, const N: usize>(/* private fields */);Expand description
A strided slice is a slice that skips over a fixed number of elements between each element.
This enables a “vertical” view of a contiguous slice, where the stride is the number of elements to skip between each element.
This is a referential type, only intended to be used as &StridedSlice<T, N>,
or in larger compositions – since it enables projecting a 2D-array view on
a 1D slice.
Implementations§
source§impl<T, const N: usize> StridedSlice<T, N>
impl<T, const N: usize> StridedSlice<T, N>
sourcepub const fn from_slice(slice: &[T]) -> &Self
pub const fn from_slice(slice: &[T]) -> &Self
Constructs this strided slice from the underlying slice
§Parameters
slice- the slice to construct from
sourcepub fn from_mut_slice(slice: &mut [T]) -> &mut Self
pub fn from_mut_slice(slice: &mut [T]) -> &mut Self
Constructs this strided slice from the underlying slice
§Parameters
slice- the slice to construct from
sourcepub const unsafe fn from_raw_parts<'a>(ptr: *const T, len: usize) -> &'a Self
pub const unsafe fn from_raw_parts<'a>(ptr: *const T, len: usize) -> &'a Self
sourcepub unsafe fn from_raw_parts_mut<'a>(ptr: *mut T, len: usize) -> &'a mut Self
pub unsafe fn from_raw_parts_mut<'a>(ptr: *mut T, len: usize) -> &'a mut Self
source§impl<T, const N: usize> StridedSlice<T, N>
impl<T, const N: usize> StridedSlice<T, N>
sourcepub const fn as_ptr(&self) -> *const T
pub const fn as_ptr(&self) -> *const T
Returns a raw pointer to the slice’s buffer.
The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
The caller must also ensure that the memory the pointer (non-transitively) points to
is never written to (except inside an UnsafeCell) using this pointer or any pointer
derived from it. If you need to mutate the contents of the slice, use [as_mut_ptr].
Modifying the container referenced by this slice may cause its buffer to be reallocated, which would also make any pointers to it invalid.
sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Returns an unsafe mutable pointer to the slice’s buffer.
The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
Modifying the container referenced by this slice may cause its buffer to be reallocated, which would also make any pointers to it invalid.
source§impl<T, const N: usize> StridedSlice<T, N>
impl<T, const N: usize> StridedSlice<T, N>
sourcepub const fn first(&self) -> Option<&T>
pub const fn first(&self) -> Option<&T>
Returns a reference to the first element of the slice, or None if it
is empty.
sourcepub fn first_mut(&mut self) -> Option<&mut T>
pub fn first_mut(&mut self) -> Option<&mut T>
Returns a mutable pointer to the first element of the slice, or None if
it is empty.
sourcepub const fn last(&self) -> Option<&T>
pub const fn last(&self) -> Option<&T>
Returns a reference to the last item in the slice, or None if it is
empty.
sourcepub fn last_mut(&mut self) -> Option<&mut T>
pub fn last_mut(&mut self) -> Option<&mut T>
Returns a mutable pointer to the last item in the slice.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
Returns a mutable iterator over the slice.