Struct SliceRef Copy item path Source pub struct SliceRef<'a, T>{ }
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
.
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 );
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());
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 );
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 );
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 )]);
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 );
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 );
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' )]);
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());
Converts this type into a shared reference of the (usually inferred) input type.
Performs copy-assignment from
source
.
Read more Formats the value using the given formatter.
Read more The resulting type after dereferencing.
Dereferences the value.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Compares and returns the maximum of two values.
Read more Compares and returns the minimum of two values.
Read more Restrict a value to a certain interval.
Read more Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self
and
other
values if one exists.
Read more Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self
and
other
) and is used by
the
>=
operator.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit
)
Performs copy-assignment from
self
to
dest
.
Read more Returns the argument unchanged.
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From <T> for U
chooses to do.
🔬 This is a nightly-only experimental API. (arbitrary_self_types
)
The target type on which the method may be called.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.