Struct soapy::Soa

source ·
pub struct Soa<T>
where T: Soapy,
{ /* private fields */ }

Implementations§

source§

impl<T> Soa<T>
where T: Soapy,

source

pub fn new() -> Self

Constructs a new, empty Soa<T>.

The container will not allocate until elements are pushed onto it.

source

pub fn with_capacity(capacity: usize) -> Self

Construct a new, empty Soa<T> with at least the specified capacity.

The container will be able to hold capacity elements without reallocating. If the capacity is 0, the container will not allocate. Note that although the returned vector has the minimum capacity specified, the vector will have a zero length. The capacity will be as specified unless T is zero-sized, in which case the capacity will be usize::MAX.

source

pub fn len(&self) -> usize

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

source

pub fn is_empty(&self) -> bool

Returns true if the container contains no elements.

source

pub fn capacity(&self) -> usize

Returns the total number of elements the container can hold without reallocating.

source

pub fn into_raw_parts(self) -> (*mut u8, usize, usize)

Decomposes a Soa<T> into its raw components.

Returns the raw pointer to the underlying data, the length of the vector (in elements), and the allocated capacity of the data (in elements). These are the same arguments in the same order as the arguments to Soa::from_raw_parts.

After calling this function, the caller is responsible for the memory previously managed by the Soa. The only way to do this is to convert the raw pointer, length, and capacity back into a Vec with the Soa::from_raw_parts function, allowing the destructor to perform the cleanup.

source

pub unsafe fn from_raw_parts( ptr: *mut u8, length: usize, capacity: usize ) -> Self

Creates a Soa<T> from a pointer, a length, and a capacity.

Safety

This is highly unsafe due to the number of invariants that aren’t checked. Given that many of these invariants are private implementation details of RawSoa, it is better not to uphold them manually. Rather, it only valid to call this method with the output of a previous call to Soa::into_raw_parts.

source

pub fn push(&mut self, element: T)

Appends an element to the back of a collection.

source

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

Removes the last element from a vector and returns it, or None if it is empty.

source

pub fn insert(&mut self, index: usize, element: T)

Inserts an element at position index, shifting all elements after it to the right.

Panics

Panics if index > len

source

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

Removes and returns the element at position index within the vector, shifting all elements after it to the left.

source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the given Soa<T>. The collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

source

pub fn reserve_exact(&mut self, additional: usize)

Reserves the minimum capacity for at least additional more elements to be inserted in the given Soa<T>. Unlike Soa::reserve, this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling reserve_exact, capacity will be greater than or equal to self.len() + additional. Does nothing if the capacity is already sufficient.

source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the container as much as possible.

source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity of the vector with a lower bound.

The capacity will remain at least as large as both the length and the supplied value. If the current capacity is less than the lower limit, this is a no-op.

source

pub fn truncate(&mut self, len: usize)

Shortens the vector, keeping the first len elements and dropping the rest.

If len is greater or equal to the vector’s current length, this has no effect. Note that this method has no effect on the allocated capacity of the vector.

source

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

Removes an element from the vector and returns it.

The removed element is replaced by the last element of the vector. This does not preserve ordering, but is O(1). If you need to preserve the element order, use remove instead.

Panics

Panics if index is out of bounds.

source

pub fn append(&mut self, other: &mut Self)

Moves all the elements of other into self, leaving other empty.

source

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

Returns an iterator over the elements.

The iterator yields all items from start to end.

source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over the elements that allows modifying each value.

The iterator yields all items from start to end.

source

pub fn try_fold<F, B>(&self, init: B, f: F) -> B
where F: FnMut(B, &T) -> ControlFlow<B, B>,

source

pub fn try_fold_zip<F, B, O>(&self, other: &Soa<O>, init: B, f: F) -> B
where O: Soapy, F: FnMut(B, &T, &O) -> ControlFlow<B, B>,

source

pub fn for_each<F>(&self, f: F)
where F: FnMut(&T),

Calls a closure on each element of the collection.

source

pub fn for_each_zip<F, O>(&self, other: &Soa<O>, f: F)
where O: Soapy, F: FnMut(&T, &O),

Calls a closure on each element of the collection.

source

pub fn clear(&mut self)

Clears the vector, removing all values.

Note that this method has no effect on the allocated capacity of the vector.

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.

source

pub fn nth_cloned(&self, index: usize) -> T
where T: Clone,

Returns a clone of the element at the given index.

Panics

Panics if index >= len.

source

pub fn nth(&self, index: usize) -> <T::RawSoa as RawSoa<T>>::Ref<'_>

Returns a reference to the element at the given index.

Panics

Panics if index >= len.

source

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

Returns slices for each of the SoA fields.

source

pub fn get_mut<I>(&mut self, index: I) -> Option<I::OutputMut<'_>>
where I: SoaIndex<T>,

Returns a mutable reference to an element or subslice depending on the type of index.

source

pub fn nth_mut(&mut self, index: usize) -> <T::RawSoa as RawSoa<T>>::RefMut<'_>

Returns a reference to the element at the given index.

Panics

Panics if index >= len.

source

pub fn slices_mut(&mut self) -> <T::RawSoa as RawSoa<T>>::SlicesMut<'_>

Returns mutable slices for each of the SoA fields.

source

pub fn swap(&mut self, a: usize, b: usize)

Swaps the position of two elements.

Panics

Panics if a or b is out of bounds.

Trait Implementations§

source§

impl<T> Clone for Soa<T>
where T: Soapy + Clone,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

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

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Soa<T>
where T: Soapy + Debug,

source§

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

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

impl<T> Default for Soa<T>
where T: Soapy,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Drop for Soa<T>
where T: Soapy,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> Extend<T> for Soa<T>
where T: Soapy,

source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> From<&[T]> for Soa<T>
where T: Soapy + Clone,

source§

fn from(value: &[T]) -> Self

Allocate a Soa<T> and fill it by cloning value’s items.

source§

impl<T, const N: usize> From<&[T; N]> for Soa<T>
where T: Soapy + Clone,

source§

fn from(value: &[T; N]) -> Self

Allocate a Soa<T> and fill it by cloning value’s items.

source§

impl<T> From<&mut [T]> for Soa<T>
where T: Soapy + Clone,

source§

fn from(value: &mut [T]) -> Self

Allocate a Soa<T> and fill it by cloning value’s items.

source§

impl<T, const N: usize> From<&mut [T; N]> for Soa<T>
where T: Soapy + Clone,

source§

fn from(value: &mut [T; N]) -> Self

Allocate a Soa<T> and fill it by cloning value’s items.

source§

impl<T, const N: usize> From<[T; N]> for Soa<T>
where T: Soapy,

source§

fn from(value: [T; N]) -> Self

Allocate a Soa<T> and move value’s items into it.

source§

impl<T> FromIterator<T> for Soa<T>
where T: Soapy,

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T> Hash for Soa<T>
where T: Soapy + 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<T> IntoIterator for Soa<T>
where T: Soapy,

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<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<T> Ord for Soa<T>
where T: Soapy + 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 + PartialOrd,

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

impl<T> PartialEq for Soa<T>
where T: Soapy + PartialEq,

source§

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

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

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

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

impl<T> PartialOrd for Soa<T>
where T: Soapy + 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

This method 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

This method 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

This method 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

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

impl<T> Eq for Soa<T>
where T: Soapy + Eq,

source§

impl<T> Send for Soa<T>
where T: Send + Soapy,

source§

impl<T> Sync for Soa<T>
where T: Sync + Soapy,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Soa<T>
where <T as Soapy>::RawSoa: RefUnwindSafe,

§

impl<T> Unpin for Soa<T>
where <T as Soapy>::RawSoa: Unpin,

§

impl<T> UnwindSafe for Soa<T>
where <T as Soapy>::RawSoa: 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
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<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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.