Struct SliceRef

Source
pub struct SliceRef<'a, T>
where T: 'a + Soapy,
{ /* private fields */ }
Expand description

An immutably borrowed Slice.

A SliceRef is a thin wrapper over a Slice that applies the same borrowing rules as an immutable reference. It is semantically equivalent to &Slice.

Methods from Deref<Target = Slice<T>>§

Source

pub fn len(&self) -> usize

Returns the number of elements in the slice, also referred to as its length.

§Examples
let soa = soa![Foo(1), Foo(2), Foo(3)];
assert_eq!(soa.len(), 3);
Source

pub fn is_empty(&self) -> bool

Returns true if the slice contains no elements.

§Examples
let mut soa = Soa::<Foo>::new();
assert!(soa.is_empty());
soa.push(Foo(1));
assert!(!soa.is_empty());
Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the elements.

The iterator yields all items from start to end.

§Examples
let soa = soa![Foo(1), Foo(2), Foo(4)];
let mut iter = soa.iter();
assert_eq!(iter.next().unwrap(), Foo(1));
assert_eq!(iter.next().unwrap(), Foo(2));
assert_eq!(iter.next().unwrap(), Foo(4));
assert_eq!(iter.next(), None);
Source

pub fn get<I>(&self, index: I) -> Option<I::Output<'_>>
where I: SoaIndex<T>,

Returns a reference to an element or subslice 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 subslice corresponding to that range, or None if out of bounds.

§Examples
let soa = soa![Foo(10), Foo(40), Foo(30), Foo(20)];
assert_eq!(soa.get(1).unwrap(), Foo(40));
assert_eq!(soa.get(4), None);
assert_eq!(soa.get(..).unwrap(), [Foo(10), Foo(40), Foo(30), Foo(20)]);
assert_eq!(soa.get(..2).unwrap(), [Foo(10), Foo(40)]);
assert_eq!(soa.get(..=2).unwrap(), [Foo(10), Foo(40), Foo(30)]);
assert_eq!(soa.get(2..).unwrap(), [Foo(30), Foo(20)]);
assert_eq!(soa.get(1..3).unwrap(), [Foo(40), Foo(30)]);
assert_eq!(soa.get(1..=3).unwrap(), [Foo(40), Foo(30), Foo(20)]);
assert_eq!(soa.get(2..5), None);
Source

pub fn idx<I>(&self, index: I) -> I::Output<'_>
where I: SoaIndex<T>,

Returns a reference to the element at the given index.

This is similar to Index, which is not implementable for this type. See get for a non-panicking version.

§Panics

Panics if the index is out-of-bounds, which is whenever SoaIndex::get returns None.

§Examples
let soa = soa![Foo(10), Foo(40), Foo(30), Foo(90)];
assert_eq!(soa.idx(3), Foo(90));
assert_eq!(soa.idx(1..3), [Foo(40), Foo(30)]);
Source

pub fn first(&self) -> Option<T::Ref<'_>>

Returns the first element of the slice, or None if empty.

§Examples
let soa = soa![Foo(10), Foo(40), Foo(30)];
assert_eq!(soa.first().unwrap(), Foo(10));

let soa = Soa::<Foo>::new();
assert_eq!(soa.first(), None);
Source

pub fn last(&self) -> Option<T::Ref<'_>>

Returns the last element of the slice, or None if empty.

§Examples
let soa = soa![Foo(10), Foo(40), Foo(30)];
assert_eq!(soa.last().unwrap(), Foo(30));

let soa = Soa::<Foo>::new();
assert_eq!(soa.last(), None);
Source

pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T>

Returns an iterator over chunk_size elements of the slice at a time, starting at the beginning of the slice.

The chunks are slices and do not overlap. If chunk_size does not divide the length of the slice, then the last up to chunk_size-1 elements will be omitted and can be retrieved from the remainder function of the iterator.

Due to each chunk having exactly chunk_size elements, the compiler can often optimize the resulting code better than in the case of chunks.

§Examples
let soa = soa![Foo('l'), Foo('o'), Foo('r'), Foo('e'), Foo('m')];
let mut iter = soa.chunks_exact(2);
assert_eq!(iter.next().unwrap(), [Foo('l'), Foo('o')]);
assert_eq!(iter.next().unwrap(), [Foo('r'), Foo('e')]);
assert!(iter.next().is_none());
assert_eq!(iter.remainder(), [Foo('m')]);
Source

pub fn slices(&self) -> T::Slices<'_>

Returns a collection of slices for each field of the slice.

For convenience, slices can also be aquired using the getter methods for individual fields.

§Examples
let soa = soa![Foo { foo: 1, bar: 2 }, Foo { foo: 3, bar: 4 }];
let slices = soa.slices();
assert_eq!(slices.foo, soa.foo());
assert_eq!(slices.bar, soa.bar());

Trait Implementations§

Source§

impl<'a, T> AsRef<Slice<T>> for SliceRef<'a, T>
where T: Soapy,

Source§

fn as_ref(&self) -> &Slice<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, T> Clone for SliceRef<'a, T>
where T: Soapy,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T> Debug for SliceRef<'a, T>
where T: Soapy, for<'b> T::Ref<'b>: Debug,

Source§

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

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

impl<'a, T> Deref for SliceRef<'a, T>
where T: Soapy,

Source§

type Target = Slice<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, T> Hash for SliceRef<'a, T>
where T: Soapy, for<'b> T::Ref<'b>: Hash,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T> IntoIterator for SliceRef<'a, T>
where T: Soapy,

Source§

type Item = <T as Soapy>::Ref<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> Ord for SliceRef<'a, T>
where T: Soapy + Ord, for<'b> T::Ref<'b>: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq<&[T]> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

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<&[T; N]> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &&[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> PartialEq<&mut [T]> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &&mut [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<&mut [T; N]> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &&mut [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> PartialEq<[T]> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

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<[T; N]> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &[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> PartialEq<Slice<T>> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &Slice<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> PartialEq<SliceMut<'_, T>> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceMut<'_, 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> PartialEq<SliceRef<'_, T>> for &[T]
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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<SliceRef<'_, T>> for &[T; N]
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for &Slice<T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for &mut [T]
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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<SliceRef<'_, T>> for &mut [T; N]
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for &mut Slice<T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for [T]
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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<SliceRef<'_, T>> for [T; N]
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for Slice<T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for SliceMut<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for Soa<T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<SliceRef<'_, T>> for Vec<T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &SliceRef<'_, 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> PartialEq<Soa<T>> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &Soa<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> PartialEq<Vec<T>> for SliceRef<'_, T>
where T: Soapy, for<'a> T::Ref<'a>: PartialEq,

Source§

fn eq(&self, other: &Vec<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<'a, T> PartialOrd for SliceRef<'a, T>
where T: Soapy, for<'b> T::Ref<'b>: PartialOrd,

Source§

fn partial_cmp(&self, other: &Self) -> 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<'a, T> Copy for SliceRef<'a, T>
where T: 'a + Soapy,

Source§

impl<'a, T> Eq for SliceRef<'_, T>
where T: Soapy, for<'b> T::Ref<'b>: Eq,

Auto Trait Implementations§

§

impl<'a, T> Freeze for SliceRef<'a, T>
where <T as Soapy>::Raw: Freeze,

§

impl<'a, T> RefUnwindSafe for SliceRef<'a, T>
where <T as Soapy>::Raw: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'a, T> Send for SliceRef<'a, T>
where <T as Soapy>::Raw: Send, T: Sync,

§

impl<'a, T> Sync for SliceRef<'a, T>
where <T as Soapy>::Raw: Sync, T: Sync,

§

impl<'a, T> Unpin for SliceRef<'a, T>
where <T as Soapy>::Raw: Unpin,

§

impl<'a, T> UnwindSafe for SliceRef<'a, T>
where <T as Soapy>::Raw: UnwindSafe, T: RefUnwindSafe,

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.