pub struct SliceRef<'a, T>where
T: 'a + Soars,{ /* private fields */ }Expand description
Methods from Deref<Target = Slice<T>>§
Sourcepub fn len(&self) -> usize
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);Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
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(), Some(FooRef(&1)));
assert_eq!(iter.next(), Some(FooRef(&2)));
assert_eq!(iter.next(), Some(FooRef(&4)));
assert_eq!(iter.next(), None);Sourcepub fn get<I>(&self, index: I) -> Option<I::Output<'_>>where
I: SoaIndex<T>,
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), Some(FooRef(&40)));
assert!(soa.get(4).is_none());
assert_eq!(soa.get(..), Some(soa![Foo(10), Foo(40), Foo(30), Foo(20)].as_slice()));
assert_eq!(soa.get(..2), Some(soa![Foo(10), Foo(40)].as_slice()));
assert_eq!(soa.get(..=2), Some(soa![Foo(10), Foo(40), Foo(30)].as_slice()));
assert_eq!(soa.get(2..), Some(soa![Foo(30), Foo(20)].as_slice()));
assert_eq!(soa.get(1..3), Some(soa![Foo(40), Foo(30)].as_slice()));
assert_eq!(soa.get(1..=3), Some(soa![Foo(40), Foo(30), Foo(20)].as_slice()));
assert!(soa.get(2..5).is_none());Sourcepub fn idx<I>(&self, index: I) -> I::Output<'_>where
I: SoaIndex<T>,
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), FooRef(&90));
assert_eq!(soa.idx(1..3), soa![Foo(40), Foo(30)]);Sourcepub fn split_at(&self, mid: usize) -> (SliceRef<'_, T>, SliceRef<'_, T>)
pub fn split_at(&self, mid: usize) -> (SliceRef<'_, T>, SliceRef<'_, T>)
Divides one slice into two at an index.
The first will contain all indices from [0, mid) (excluding
the index mid itself) and the second will contain all
indices from [mid, len) (excluding the index len itself).
§Panics
Panics if mid > len. For a non-panicking alternative see
split_at_checked.
§Examples
let soa = soa![Foo(1), Foo(2), Foo(3), Foo(4), Foo(5)];
let (l, r) = soa.split_at(3);
assert_eq!(l, soa![Foo(1), Foo(2), Foo(3)]);
assert_eq!(r, soa![Foo(4), Foo(5)]);Sourcepub fn split_at_checked(
&self,
mid: usize,
) -> Option<(SliceRef<'_, T>, SliceRef<'_, T>)>
pub fn split_at_checked( &self, mid: usize, ) -> Option<(SliceRef<'_, T>, SliceRef<'_, T>)>
Divides one slice into two at an index,
returning None if the slice is too short.
If mid ≤ len returns a pair of slices where the first will contain all
indices from [0, mid) (excluding the index mid itself) and the
second will contain all indices from [mid, len) (excluding the index
len itself).
Otherwise, if mid > len, returns None.
§Examples
let soa = soa![Foo(1), Foo(2), Foo(3), Foo(4)];
{
let (l, r) = soa.split_at_checked(0).unwrap();
assert_eq!(l, soa![]);
assert_eq!(r, soa);
}
{
let (l, r) = soa.split_at_checked(2).unwrap();
assert_eq!(l, soa![Foo(1), Foo(2)]);
assert_eq!(r, soa![Foo(3), Foo(4)]);
}
{
let (l, r) = soa.split_at_checked(4).unwrap();
assert_eq!(l, soa);
assert_eq!(r, soa![]);
}
assert_eq!(None, soa.split_at_checked(5));Sourcepub unsafe fn split_at_unchecked(
&self,
mid: usize,
) -> (SliceRef<'_, T>, SliceRef<'_, T>)
pub unsafe fn split_at_unchecked( &self, mid: usize, ) -> (SliceRef<'_, T>, SliceRef<'_, T>)
Divides one slice into two at an index without doing bounds checking.
The first will contain all indices from [0, mid) (excluding
the index mid itself) and the second will contain all
indices from [mid, len) (excluding the index len itself).
For a safe alternative, see split_at.
§Safety
Calling this method with an out-of-bounds index is undefined behavior, even if the resulting reference is not used.
§Examples
let soa = soa![Foo(1), Foo(2), Foo(3)];
let (l, r) = unsafe { soa.split_at_unchecked(2) };
assert_eq!(l, soa![Foo(1), Foo(2)]);
assert_eq!(r, soa![Foo(3)]);Sourcepub fn first(&self) -> Option<T::Ref<'_>>
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(), Some(FooRef(&10)));
let soa = Soa::<Foo>::new();
assert_eq!(soa.first(), None);Sourcepub fn last(&self) -> Option<T::Ref<'_>>
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(), Some(FooRef(&30)));
let soa = Soa::<Foo>::new();
assert_eq!(soa.last(), None);Sourcepub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> ⓘ
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(), Some(soa![Foo('l'), Foo('o')].as_slice()));
assert_eq!(iter.next(), Some(soa![Foo('r'), Foo('e')].as_slice()));
assert!(iter.next().is_none());
assert_eq!(iter.remainder(), &soa![Foo('m')]);Sourcepub fn slices(&self) -> T::Slices<'_>
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> IntoIterator for SliceRef<'a, T>where
T: Soars,
impl<'a, T> IntoIterator for SliceRef<'a, T>where
T: Soars,
Source§impl<T> Ord for SliceRef<'_, T>
impl<T> Ord for SliceRef<'_, T>
Source§impl<T> PartialOrd for SliceRef<'_, T>
impl<T> PartialOrd for SliceRef<'_, T>
impl<'a, T> Copy for SliceRef<'a, T>where
T: 'a + Soars,
impl<T> Eq for SliceRef<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for SliceRef<'a, T>
impl<'a, T> RefUnwindSafe for SliceRef<'a, T>
impl<'a, T> Send for SliceRef<'a, T>
impl<'a, T> Sync for SliceRef<'a, T>where
T: Sync,
impl<'a, T> Unpin for SliceRef<'a, T>
impl<'a, T> UnwindSafe for SliceRef<'a, T>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)