Struct stride::Stride [−][src]
A constant strided slice.
Implementations
impl<T, const S: usize> Stride<T, S>
[src]
pub fn new(data: &[T]) -> &Self
[src]
Constructs a new strided slice.
Examples
let data = &[1, 2, 3, 4, 5, 6]; let stride = Stride::<_, 3>::new(data);
pub fn new_mut(data: &mut [T]) -> &mut Self
[src]
Constructs a new mutable strided slice.
Examples
let data = &mut [1, 2, 3, 4, 5, 6]; let stride = Stride::<_, 3>::new_mut(data);
pub const fn len(&self) -> usize
[src]
Returns the number of elements in the strided slice.
This is equivalent to the ceiling division of the underlying slice
length by S
.
Examples
let data = &[1, 2, 3, 4, 5, 6]; assert_eq!(Stride::<_, 1>::new(data).len(), 6); assert_eq!(Stride::<_, 2>::new(data).len(), 3); assert_eq!(Stride::<_, 3>::new(data).len(), 2);
pub const fn is_empty(&self) -> bool
[src]
Returns true
if the strided slice has a length of 0.
Examples
let stride = Stride::<_, 3>::new(&[1, 2, 3, 4, 5, 6]); assert!(!stride.is_empty());
pub const fn as_ptr(&self) -> *const T
[src]
Returns a raw pointer to the underlying slice's buffer.
See slice::as_ptr()
.
pub fn as_mut_ptr(&mut self) -> *mut T
[src]
Returns an unsafe mutable pointer to the underlying slice's buffer.
See slice::as_mut_ptr()
.
pub fn get<I>(&self, index: I) -> Option<&I::Output> where
I: StrideIndex<Stride<T, S>>,
[src]
I: StrideIndex<Stride<T, S>>,
Returns a reference to an element or substride depending on the type of index.
- If given a position, returns a reference to the element at that
position or
None
if out of bounds. - If given a range, returns the substride corresponding to that range,
or
None
if out of bounds.
Examples
let stride = Stride::<_, 2>::new(&[1, 2, 3, 4, 5, 6]); assert_eq!(stride.get(1), Some(&3)); assert_eq!(stride.get(0..2), Some(Stride::<_, 2>::new(&[1, 2, 3, 4]))); assert_eq!(stride.get(3), None); assert_eq!(stride.get(0..4), None);
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output> where
I: StrideIndex<Stride<T, S>>,
[src]
I: StrideIndex<Stride<T, S>>,
Returns a mutable reference to an element or substride depending on the
type of index (see get
) or None
if the index is out of bounds.
Examples
let data = &mut [0, 1, 2, 3]; let stride = Stride::<_, 2>::new_mut(data); if let Some(elem) = stride.get_mut(1) { *elem = 42; } assert_eq!(stride, Stride::<_, 2>::new(&[0, 1, 42, 3]));
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output where
I: StrideIndex<Self>,
[src]
I: StrideIndex<Self>,
Returns a reference to an element or substride, without doing bounds checking.
For a safe alternative see get
.
Safety
Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output where
I: StrideIndex<Self>,
[src]
I: StrideIndex<Self>,
Returns a mutable reference to an element or substride, without doing bounds checking.
For a safe alternative see get_mut
.
Safety
Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.
pub fn first(&self) -> Option<&T>
[src]
Returns a reference to the first element of the strided slice, or None
if it is empty.
pub fn first_mut(&mut self) -> Option<&mut T>
[src]
Returns a mutable reference to the first element of the strided slice,
or None
if it is empty.
pub fn last(&self) -> Option<&T>
[src]
Returns a reference to the last element of the strided slice, or None
if it is empty.
pub fn last_mut(&mut self) -> Option<&mut T>
[src]
Returns a mutable reference to the last element of the strided slice, or
None
if it is empty.
pub fn swap(&mut self, a: usize, b: usize)
[src]
Swaps two elements in the strided slice.
Arguments
a
- The index of the first elementb
- The index of the second element
Panics
If a
or b
are out of bounds.
pub fn iter(&self) -> Iter<'_, T, S>ⓘ
[src]
Returns an iterator over the stride.
Examples
let stride = Stride::<_, 2>::new(&[1, 2, 3, 4, 5, 6]); let mut iterator = stride.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&3)); assert_eq!(iterator.next(), Some(&5)); assert_eq!(iterator.next(), None);
pub fn iter_mut(&mut self) -> IterMut<'_, T, S>ⓘ
[src]
Returns an iterator over the stride that allows modifying each value.
Examples
let slice = &mut [1, 1, 2, 2, 3, 3]; let stride = Stride::<_, 2>::new_mut(slice); for elem in stride.iter_mut() { *elem *= 2; } assert_eq!(slice, &[2, 1, 4, 2, 6, 3]);
impl<T> Stride<T, 1>
[src]
pub fn as_slice(&self) -> &[T]
[src]
Returns a slice containing the entire strided slice.
Only available on strided slices with a stride of 1
.
Examples
let slice = &[1, 2, 3]; let stride = Stride::<_, 1>::new(slice); assert_eq!(stride.as_slice(), slice);
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
Returns a mutable slice containing the entire strided slice.
Only available on strided slices with a stride of 1
.
Examples
let slice = &mut [1, 2, 7]; let stride = Stride::<_, 1>::new_mut(slice); stride.as_mut_slice()[2] = 3; assert_eq!(slice, &[1, 2, 3])
Trait Implementations
impl<T, const S: usize> Debug for Stride<T, S> where
T: Debug,
[src]
T: Debug,
impl<T, const S: usize> Default for &Stride<T, S>
[src]
impl<T, const S: usize> Default for &mut Stride<T, S>
[src]
impl<T, const S: usize> Eq for Stride<T, S> where
T: Eq,
[src]
T: Eq,
impl<T, const S: usize> Hash for Stride<T, S> where
T: Hash,
[src]
T: Hash,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<I, T, const S: usize> Index<I> for Stride<T, S> where
I: StrideIndex<Self>,
[src]
I: StrideIndex<Self>,
type Output = I::Output
The returned type after indexing.
fn index(&self, index: I) -> &Self::Output
[src]
impl<I, T, const S: usize> IndexMut<I> for Stride<T, S> where
I: StrideIndex<Self>,
[src]
I: StrideIndex<Self>,
impl<'a, T, const S: usize> IntoIterator for &'a Stride<T, S>
[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T, S>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, T, S>ⓘ
[src]
impl<'a, T, const S: usize> IntoIterator for &'a mut Stride<T, S>
[src]
type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T, S>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IterMut<'a, T, S>ⓘ
[src]
impl<T, const S: usize> Ord for Stride<T, S> where
T: Ord,
[src]
T: Ord,
fn cmp(&self, other: &Stride<T, S>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T, U, const S: usize, const N: usize> PartialEq<&'_ [U; N]> for Stride<T, S> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
fn eq(&self, other: &&[U; N]) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T, U, const S: usize> PartialEq<&'_ [U]> for Stride<T, S> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T, U, const S: usize, const N: usize> PartialEq<[U; N]> for Stride<T, S> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T, U, const S: usize> PartialEq<[U]> for Stride<T, S> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T, U, const S: usize, const R: usize> PartialEq<Stride<U, R>> for Stride<T, S> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
fn eq(&self, other: &Stride<U, R>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T, U, const S: usize, const R: usize> PartialOrd<Stride<U, R>> for Stride<T, S> where
T: PartialOrd<U>,
[src]
T: PartialOrd<U>,
fn partial_cmp(&self, other: &Stride<U, R>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T, const S: usize> StrideIndex<Stride<T, S>> for usize
[src]
type Output = T
The output type returned by methods.
fn get(self, stride: &Stride<T, S>) -> Option<&Self::Output>
[src]
fn get_mut(self, stride: &mut Stride<T, S>) -> Option<&mut Self::Output>
[src]
unsafe fn get_unchecked(
self,
stride: *const Stride<T, S>
) -> *const Self::Output
[src]
self,
stride: *const Stride<T, S>
) -> *const Self::Output
unsafe fn get_unchecked_mut(
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
[src]
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
fn index(self, stride: &Stride<T, S>) -> &Self::Output
[src]
fn index_mut(self, stride: &mut Stride<T, S>) -> &mut Self::Output
[src]
impl<T, const S: usize> StrideIndex<Stride<T, S>> for Range<usize>
[src]
type Output = Stride<T, S>
The output type returned by methods.
fn get(self, stride: &Stride<T, S>) -> Option<&Self::Output>
[src]
fn get_mut(self, stride: &mut Stride<T, S>) -> Option<&mut Self::Output>
[src]
unsafe fn get_unchecked(
self,
stride: *const Stride<T, S>
) -> *const Self::Output
[src]
self,
stride: *const Stride<T, S>
) -> *const Self::Output
unsafe fn get_unchecked_mut(
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
[src]
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
fn index(self, stride: &Stride<T, S>) -> &Self::Output
[src]
fn index_mut(self, stride: &mut Stride<T, S>) -> &mut Self::Output
[src]
impl<T, const S: usize> StrideIndex<Stride<T, S>> for RangeFrom<usize>
[src]
type Output = Stride<T, S>
The output type returned by methods.
fn get(self, stride: &Stride<T, S>) -> Option<&Self::Output>
[src]
fn get_mut(self, stride: &mut Stride<T, S>) -> Option<&mut Self::Output>
[src]
unsafe fn get_unchecked(
self,
stride: *const Stride<T, S>
) -> *const Self::Output
[src]
self,
stride: *const Stride<T, S>
) -> *const Self::Output
unsafe fn get_unchecked_mut(
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
[src]
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
fn index(self, stride: &Stride<T, S>) -> &Self::Output
[src]
fn index_mut(self, stride: &mut Stride<T, S>) -> &mut Self::Output
[src]
impl<T, const S: usize> StrideIndex<Stride<T, S>> for RangeFull
[src]
type Output = Stride<T, S>
The output type returned by methods.
fn get(self, stride: &Stride<T, S>) -> Option<&Self::Output>
[src]
fn get_mut(self, stride: &mut Stride<T, S>) -> Option<&mut Self::Output>
[src]
unsafe fn get_unchecked(
self,
stride: *const Stride<T, S>
) -> *const Self::Output
[src]
self,
stride: *const Stride<T, S>
) -> *const Self::Output
unsafe fn get_unchecked_mut(
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
[src]
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
fn index(self, stride: &Stride<T, S>) -> &Self::Output
[src]
fn index_mut(self, stride: &mut Stride<T, S>) -> &mut Self::Output
[src]
impl<T, const S: usize> StrideIndex<Stride<T, S>> for RangeInclusive<usize>
[src]
type Output = Stride<T, S>
The output type returned by methods.
fn get(self, stride: &Stride<T, S>) -> Option<&Self::Output>
[src]
fn get_mut(self, stride: &mut Stride<T, S>) -> Option<&mut Self::Output>
[src]
unsafe fn get_unchecked(
self,
stride: *const Stride<T, S>
) -> *const Self::Output
[src]
self,
stride: *const Stride<T, S>
) -> *const Self::Output
unsafe fn get_unchecked_mut(
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
[src]
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
fn index(self, stride: &Stride<T, S>) -> &Self::Output
[src]
fn index_mut(self, stride: &mut Stride<T, S>) -> &mut Self::Output
[src]
impl<T, const S: usize> StrideIndex<Stride<T, S>> for RangeTo<usize>
[src]
type Output = Stride<T, S>
The output type returned by methods.
fn get(self, stride: &Stride<T, S>) -> Option<&Self::Output>
[src]
fn get_mut(self, stride: &mut Stride<T, S>) -> Option<&mut Self::Output>
[src]
unsafe fn get_unchecked(
self,
stride: *const Stride<T, S>
) -> *const Self::Output
[src]
self,
stride: *const Stride<T, S>
) -> *const Self::Output
unsafe fn get_unchecked_mut(
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
[src]
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
fn index(self, stride: &Stride<T, S>) -> &Self::Output
[src]
fn index_mut(self, stride: &mut Stride<T, S>) -> &mut Self::Output
[src]
impl<T, const S: usize> StrideIndex<Stride<T, S>> for RangeToInclusive<usize>
[src]
type Output = Stride<T, S>
The output type returned by methods.
fn get(self, stride: &Stride<T, S>) -> Option<&Self::Output>
[src]
fn get_mut(self, stride: &mut Stride<T, S>) -> Option<&mut Self::Output>
[src]
unsafe fn get_unchecked(
self,
stride: *const Stride<T, S>
) -> *const Self::Output
[src]
self,
stride: *const Stride<T, S>
) -> *const Self::Output
unsafe fn get_unchecked_mut(
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
[src]
self,
stride: *mut Stride<T, S>
) -> *mut Self::Output
fn index(self, stride: &Stride<T, S>) -> &Self::Output
[src]
fn index_mut(self, stride: &mut Stride<T, S>) -> &mut Self::Output
[src]
Auto Trait Implementations
impl<T, const S: usize> Send for Stride<T, S> where
T: Send,
[src]
T: Send,
impl<T, const S: usize> Sync for Stride<T, S> where
T: Sync,
[src]
T: Sync,
impl<T, const S: usize> Unpin for Stride<T, S> where
T: Unpin,
[src]
T: Unpin,