Trait shard_ecs::ComponentAllocator[][src]

pub unsafe trait ComponentAllocator<'s, C: Component> {
    type RefType: RefTuple<'s>;
    type MutRefType: MutTuple<'s>;
    type SliceType: SliceTuple;
    type MutSliceType: MutSliceTuple;

    const ALLOCATION_ALIGNMENT: usize;
    const ALLOCATION_SIZE: fn(_: u16) -> usize;
    const POOL_STRIDE: fn(_: u16) -> usize;

    unsafe fn get_component(pool_ptr: *const u8, index: u16) -> Self::RefType;
unsafe fn get_component_mut(
        pool_ptr: *mut u8,
        index: u16
    ) -> Self::MutRefType;
unsafe fn get_component_slice(
        pool_ptr: *const u8,
        len: usize
    ) -> Self::SliceType;
unsafe fn get_component_slice_mut(
        pool_ptr: *mut u8,
        len: usize
    ) -> Self::MutSliceType;
unsafe fn write_component_memory(
        pool_ptr: *mut u8,
        index: u16,
        source: *const u8
    );
unsafe fn read_component_memory(
        pool_ptr: *const u8,
        index: u16,
        destination: *mut u8
    );
unsafe fn move_component(
        source_pool: *const u8,
        source_index: u16,
        destination_pool: *mut u8,
        destination_index: u16
    );
unsafe fn drop_component_memory(pool_ptr: *mut u8, index: u16); }
Expand description

Custom component allocator trait. The allocator determines the alignment of a memory allocation (default = 4096 components per alloc).

Safety

  • COMPONENT_COUNT_IN_ALLOC must be a multiple of COMPONENTS_IN_POOL.
  • The allocator MUST align all memory accesses.

Associated Types

Associated Constants

Required methods

Returns a reference to the component in the pool at index.

Safety

  • index must be within the pools size.
  • Other safety guarantees determined by trait implementation.

Returns a mutable reference to the component in the pool at index.

Safety

  • index must be within the pools size.
  • Other safety guarantees determined by trait implementation.

Returns a slice to the components in the given pool.

Safety

  • len must be within the pools size.
  • Other safety guarantees determined by trait implementation.

Returns a mutable slice to the components in the given pool.

Safety

  • len must be within the pools size.
  • Other safety guarantees determined by trait implementation.

Writes a component into the pool from the source pointer.

Safety

  • src and dst pointers MUST not overlap. Does not call drop.
  • Destination pointer MUST be correctly aligned. (It must be a valid component pointer).

Reads a component from a pool to the given destination pointer.

Safety

  • src and dst pointers MUST not overlap. Does not call drop.
  • Destination pointer MUST be correctly aligned. (It must be a valid component pointer).

Moves a component from the source pool into the destination pool. Does not call drop.

Safety

  • src and dst pointers MUST not overlap. Does not call drop.

Calls the drop handler on the component at the given index.

Safety

  • index must be within the pools size.
  • index must be within the pool.

Implementors