Trait RawSoa

Source
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

Required Associated Types§

Source

type Slices<'a> where Self: 'a

For each field with type F in T, Slices has a field with type &[F]

Source

type SlicesMut<'a> where Self: 'a

For each field with type F in T, SlicesMut has a field with type &mut [F]

Source

type Ref<'a> where Self: 'a

For each field with type F in T, Ref has a field with type &F

Source

type RefMut<'a> where Self: 'a

For each field with type F in T, RefMut has a field with type &mut F

Required Methods§

Source

fn dangling() -> Self

Creates a Self with dangling pointers for all its fields and without allocating memory.

Source

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 <= end
  • start <= PREV_LEN
  • end <= PREV_LEN
Source

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 <= end
  • start <= PREV_LEN
  • end <= PREV_LEN
Source

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 == 0
  • size_of::<T>() == 0
Source

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.

Source

unsafe fn alloc(capacity: usize) -> Self

Allocates room for capacity elements.

§Safety

The caller must ensure that

Source

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>() > 0
  • new_capacity > old_capacity
  • length <= old_capacity
  • old_capacity > 0 (Otherwise use RawSoa::alloc)
Source

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>() > 0
  • new_capacity < old_capacity
  • length <= new_capacity
  • old_capacity > 0 (Otherwise use RawSoa::dealloc)
Source

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>() > 0
  • old_capacity > 0
Source

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_CAP
  • dst < PREV_CAP
  • src + count <= PREV_CAP
  • dst + count <= PREV_CAP
Source

unsafe fn set(&mut self, index: usize, element: T)

Sets the element at index to element.

§Safety

The caller must ensure that

  • index < PREV_CAP
Source

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
Source

unsafe fn get_ref<'a>(&self, index: usize) -> Self::Ref<'a>

Gets a reference to the element at index.

§Safety

The caller must ensure that

  • index < PREV_CAP
Source

unsafe fn get_mut<'a>(&self, index: usize) -> Self::RefMut<'a>

Gets a mutable reference to the element at index.

§Safety

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.

Implementors§