pub trait RawSoa<T>: Copy + Clone {
type Slices<'a>
where Self: 'a;
type SlicesMut<'a>
where Self: 'a;
type Ref<'a>
where Self: 'a;
type RefMut<'a>
where Self: 'a;
Show 14 methods
// Required methods
fn dangling() -> Self;
unsafe fn slices(&self, start: usize, end: usize) -> Self::Slices<'_>;
unsafe fn slices_mut(
&mut self,
start: usize,
end: usize,
) -> Self::SlicesMut<'_>;
fn as_ptr(self) -> *mut u8;
unsafe fn from_parts(ptr: *mut u8, capacity: usize) -> Self;
unsafe fn alloc(capacity: usize) -> Self;
unsafe fn realloc_grow(
&mut self,
old_capacity: usize,
new_capacity: usize,
length: usize,
);
unsafe fn realloc_shrink(
&mut self,
old_capacity: usize,
new_capacity: usize,
length: usize,
);
unsafe fn dealloc(self, old_capacity: usize);
unsafe fn copy(&mut self, src: usize, dst: usize, count: usize);
unsafe fn set(&mut self, index: usize, element: T);
unsafe fn get(&self, index: usize) -> T;
unsafe fn get_ref<'a>(&self, index: usize) -> Self::Ref<'a>;
unsafe fn get_mut<'a>(&self, index: usize) -> Self::RefMut<'a>;
}Expand description
A low-level utility providing fundamental operations needed by Soa<T>
In particular, it manages an allocation and a set of pointers into
the allocation. Each of the pointers corresponds to a field of the type T
and is treated as an array of values of that field’s type.
§Safety
Use of this type is inherently unsafe and should be restricted to the
implementation of Soa. There is no guarantee of contract stability between
versions. Further, this type will neither deallocate its memory nor
drop its contents when it is dropped. Special care must be taken to avoid
unsound use.
In the method documentation, it is established that PREV_CAP is
- 0 if no previous calls to
RawSoa::realloc_groworRawSoa::realloc_shrinkhave been made, or - the same value as was used for
new_capacityin previous calls toRawSoa::realloc_growandRawSoa::realloc_shrink
Required Associated Types§
Sourcetype Slices<'a>
where
Self: 'a
type Slices<'a> where Self: 'a
For each field with type F in T, Slices has a field with type
&[F]
Required Methods§
Sourcefn dangling() -> Self
fn dangling() -> Self
Creates a Self with dangling pointers for all its fields and without
allocating memory.
Sourceunsafe fn slices(&self, start: usize, end: usize) -> Self::Slices<'_>
unsafe fn slices(&self, start: usize, end: usize) -> Self::Slices<'_>
Constructs safe, immutable slices of the arrays managed by Self with
the range start..end.
§Safety
The caller must ensure that
start <= endstart <= PREV_LENend <= PREV_LEN
Sourceunsafe fn slices_mut(&mut self, start: usize, end: usize) -> Self::SlicesMut<'_>
unsafe fn slices_mut(&mut self, start: usize, end: usize) -> Self::SlicesMut<'_>
Constructs safe, mutable slices of the arrays managed by Self with the
range start..end.
§Safety
The caller must ensure that
start <= endstart <= PREV_LENend <= PREV_LEN
Sourcefn as_ptr(self) -> *mut u8
fn as_ptr(self) -> *mut u8
Returns the pointer that contains the allocated capacity.
The pointer will point to invalid memory in these circumstances:
PREV_CAP == 0size_of::<T>() == 0
Sourceunsafe fn from_parts(ptr: *mut u8, capacity: usize) -> Self
unsafe fn from_parts(ptr: *mut u8, capacity: usize) -> Self
Construct a new Self with the given pointer and capacity.
§Safety
The pointer should come from a previous instance of Self with
PREV_CAP == capacity.
Sourceunsafe fn alloc(capacity: usize) -> Self
unsafe fn alloc(capacity: usize) -> Self
Allocates room for capacity elements.
§Safety
The caller must ensure that
size_of::<T>() > 0capacity > 0PREV_CAP == 0(Otherwise useRawSoa::realloc_grow)
Sourceunsafe fn realloc_grow(
&mut self,
old_capacity: usize,
new_capacity: usize,
length: usize,
)
unsafe fn realloc_grow( &mut self, old_capacity: usize, new_capacity: usize, length: usize, )
Grows the allocation with room for old_capacity elements to fit
new_capacity elements and moves length number of array elements to
their new locations.
§Safety
The caller must ensure that
size_of::<T>() > 0new_capacity > old_capacitylength <= old_capacityold_capacity > 0(Otherwise useRawSoa::alloc)
Sourceunsafe fn realloc_shrink(
&mut self,
old_capacity: usize,
new_capacity: usize,
length: usize,
)
unsafe fn realloc_shrink( &mut self, old_capacity: usize, new_capacity: usize, length: usize, )
Shrinks the allocation with room for old_capacity elements to fit
new_capacity elements and moves length number of array elements to
their new locations.
§Safety
The caller must ensure that
size_of::<T>() > 0new_capacity < old_capacitylength <= new_capacityold_capacity > 0(Otherwise useRawSoa::dealloc)
Sourceunsafe fn dealloc(self, old_capacity: usize)
unsafe fn dealloc(self, old_capacity: usize)
Deallocates the allocation with room for capacity elements. The state
after calling this method is equivalent to RawSoa::dangling.
§Safety
Self no longer valid after calling this function. The caller must ensure that
size_of::<T>() > 0old_capacity > 0
Sourceunsafe fn copy(&mut self, src: usize, dst: usize, count: usize)
unsafe fn copy(&mut self, src: usize, dst: usize, count: usize)
Copies count elements from src index to dst index in each of the
arrays.
§Safety
The caller must ensure that
src < PREV_CAPdst < PREV_CAPsrc + count <= PREV_CAPdst + count <= PREV_CAP
Sourceunsafe fn get(&self, index: usize) -> T
unsafe fn get(&self, index: usize) -> T
Gets the element at index.
§Safety
After calling get, the element at index should be treated as having
been moved out of Self and into the caller. Therefore, it is no longer
valid to reference this array element either by value or by reference.
The caller must ensure that
index < PREV_CAP
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.