alloy::core

Struct StridedSlice

source
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>

source

pub const fn from_slice(slice: &[T]) -> &Self

Constructs this strided slice from the underlying slice

§Parameters
  • slice - the slice to construct from
source

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
source

pub const unsafe fn from_raw_parts<'a>(ptr: *const T, len: usize) -> &'a Self

Constructs this strided slice from a raw pointer and length

§Parameters
  • ptr - the pointer to the slice
  • len - the length of the slice
§Safety

The caller must ensure that the pointer is valid and that the length is within the bounds of the slice.

source

pub unsafe fn from_raw_parts_mut<'a>(ptr: *mut T, len: usize) -> &'a mut Self

Constructs this mutable strided slice from a raw pointer and length

§Parameters
  • ptr - the pointer to the slice
  • len - the length of the slice
§Safety

The caller must ensure that the pointer is valid and that the length is within the bounds of the slice.

source§

impl<T, const N: usize> StridedSlice<T, N>

source

pub const fn len(&self) -> usize

Returns the number of elements in the strided slice.

source

pub const fn is_empty(&self) -> bool

Returns true if the slice has a length of 0.

source

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.

source

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>

source

pub const fn first(&self) -> Option<&T>

Returns a reference to the first element of the slice, or None if it is empty.

source

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.

source

pub const fn last(&self) -> Option<&T>

Returns a reference to the last item in the slice, or None if it is empty.

source

pub fn last_mut(&mut self) -> Option<&mut T>

Returns a mutable pointer to the last item in the slice.

source

pub fn iter(&self) -> impl Iterator<Item = &T>

Returns an iterator over the slice.

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Returns a mutable iterator over the slice.

source

pub const unsafe fn index_unchecked(&self, index: usize) -> &T

Retrieves the value at the given index without doing proper bounds checking.

§Parameters
  • index - the index to access
§Safety

index must be within the reachable bounds of the slice, or the result is undefined behavior.

source

pub unsafe fn index_mut_unchecked(&mut self, index: usize) -> &mut T

Retrieves the a mutable reference to the given index without doing proper bounds checking.

§Parameters
  • index - the index to access
§Safety

index must be within the reachable bounds of the slice, or the result is undefined behavior.

Trait Implementations§

source§

impl<T, const N: usize> Debug for StridedSlice<T, N>
where T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, const N: usize> Index<Range<usize>> for StridedSlice<T, N>

source§

type Output = StridedSlice<T, N>

The returned type after indexing.
source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> Index<RangeFrom<usize>> for StridedSlice<T, N>

source§

type Output = StridedSlice<T, N>

The returned type after indexing.
source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> Index<RangeFull> for StridedSlice<T, N>

source§

type Output = StridedSlice<T, N>

The returned type after indexing.
source§

fn index(&self, _: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> Index<RangeInclusive<usize>> for StridedSlice<T, N>

source§

type Output = StridedSlice<T, N>

The returned type after indexing.
source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> Index<RangeTo<usize>> for StridedSlice<T, N>

source§

type Output = StridedSlice<T, N>

The returned type after indexing.
source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> Index<RangeToInclusive<usize>> for StridedSlice<T, N>

source§

type Output = StridedSlice<T, N>

The returned type after indexing.
source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> Index<usize> for StridedSlice<T, N>

source§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<Range<usize>> for StridedSlice<T, N>

source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<RangeFrom<usize>> for StridedSlice<T, N>

source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<RangeFull> for StridedSlice<T, N>

source§

fn index_mut(&mut self, _: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<RangeInclusive<usize>> for StridedSlice<T, N>

source§

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<RangeTo<usize>> for StridedSlice<T, N>

source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<RangeToInclusive<usize>> for StridedSlice<T, N>

source§

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<usize> for StridedSlice<T, N>

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> PartialEq<&[T]> for StridedSlice<T, N>
where T: PartialEq<T>,

source§

fn eq(&self, other: &&[T]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, const N: usize> PartialEq<StridedSlice<T, N>> for &[T]
where T: PartialEq<T>,

source§

fn eq(&self, other: &StridedSlice<T, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, const S: usize> PartialEq for &StridedSlice<T, S>
where T: PartialEq<T>,

source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, const N: usize> PartialOrd<&[T]> for StridedSlice<T, N>
where T: PartialOrd<T>,

source§

fn partial_cmp(&self, other: &&[T]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, const N: usize> PartialOrd<StridedSlice<T, N>> for &[T]
where T: PartialOrd<T>,

source§

fn partial_cmp(&self, other: &StridedSlice<T, N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for StridedSlice<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for StridedSlice<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for StridedSlice<T, N>
where T: Send,

§

impl<T, const N: usize> !Sized for StridedSlice<T, N>

§

impl<T, const N: usize> Sync for StridedSlice<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for StridedSlice<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for StridedSlice<T, N>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more