Trait AddEntity

Source
pub trait AddEntity: RegisterComponent {
    // Required methods
    fn to_value_index(&self, ri: usize) -> Option<usize>;
    fn begin_add_row(&mut self);
    unsafe fn add_value(&mut self, ci: usize, val_ptr: NonNull<u8>);
    unsafe fn end_add_row(&mut self) -> usize;
    fn value_ptr_by_value_index(
        &self,
        ci: usize,
        vi: usize,
    ) -> Option<NonNull<u8>>;
    unsafe fn begin_remove_row_by_value_index(&mut self, vi: usize);
    unsafe fn remove_value_by_value_index(
        &mut self,
        ci: usize,
        vi: usize,
        buf: NonNull<u8>,
    );
    unsafe fn drop_value_by_value_index(&mut self, ci: usize, vi: usize);
    unsafe fn forget_value_by_value_index(&mut self, ci: usize, vi: usize);
    unsafe fn end_remove_row_by_value_index(&mut self, vi: usize);

    // Provided methods
    fn remove_row(&mut self, ri: usize) -> bool { ... }
    fn remove_row_by_value_index(&mut self, vi: usize) { ... }
}
Expand description

A trait for adding or removing component values from an entity container.

See ContainEntity for more information.

Required Methods§

Source

fn to_value_index(&self, ri: usize) -> Option<usize>

Converts given row index to value index.

Source

fn begin_add_row(&mut self)

Starts inserting component values of an entity to the entity container.

§Panics

May panic if any component columns were borrowed and not returned yet. But implementations must guarantee that one of AddEntity::begin_add_row, AddEntity::add_value, and AddEntity::end_add_row panics if borrowed component column is detected.

§Safety

This method must be followed by AddEntity::add_value and AddEntity::end_add_row.

§Examples

See ContainEntity document.

Source

unsafe fn add_value(&mut self, ci: usize, val_ptr: NonNull<u8>)

Inserts a component value of an entity in the entity container.

This method creates a bitwise copy of the value, so that caller must not access the value in any ways including its drop procedure after calling this method.

§Panics

See AddEntity::begin_add_row document.

§Safety

Caller must guarantee

  • This method must be called between AddEntity::begin_add_row and AddEntity::end_add_row for all components.
  • Column index ci is not out of bounds.
  • Value pointer val_ptr is valid for the component column type.
  • Value must not be accessed after calling this method even drop().
§Examples

See ContainEntity document.

Source

unsafe fn end_add_row(&mut self) -> usize

Finishes inserting component values of an entity in the entity container then returns row index to the inserted entity.

§Panics

See AddEntity::begin_add_row document.

§Safety

Caller must have called AddEntity::begin_add_row once and AddEntity::add_value number of component columns times before calling to this method for just one entity.

§Examples

See ContainEntity document.

Source

fn value_ptr_by_value_index(&self, ci: usize, vi: usize) -> Option<NonNull<u8>>

Retrieves a pointer to a component value for the given column and value indices.

If the given index is out of bounds, returns None.

Source

unsafe fn begin_remove_row_by_value_index(&mut self, vi: usize)

Starts removing component values of an entity from the entity container.

§Panics

May panic if any component columns were borrowed and not returned yet. But implementations must guarantee that one of methods below panic if borrowed component column is detected.

§Safety

Caller must guarantee

Source

unsafe fn remove_value_by_value_index( &mut self, ci: usize, vi: usize, buf: NonNull<u8>, )

Removes a component value of an entity in the entity container then write it to the given buffer.

Caller must choose one of methods below to take a component value out.

§Panics

See AddEntity::begin_remove_row_by_value_index document.

§Safety

Caller must guarantee

Source

unsafe fn drop_value_by_value_index(&mut self, ci: usize, vi: usize)

Drops a component value of an entity in the entity container.

Caller must choose one of methods below to take a component value out.

§Panics

See AddEntity::begin_remove_row_by_value_index document.

§Safety

Caller must guarantee

Source

unsafe fn forget_value_by_value_index(&mut self, ci: usize, vi: usize)

Removes and forgets a component value of an entity in the entity container.

Caller must choose one of methods below to take a component value out.

§Panics

See AddEntity::begin_remove_row_by_value_index document.

§Safety

See AddEntity::drop_value_by_value_index.

Source

unsafe fn end_remove_row_by_value_index(&mut self, vi: usize)

Finishes removing component values of an entity in the entity container.

§Panics

See AddEntity::begin_remove_row_by_value_index document.

§Safety

Caller must guarantee

Provided Methods§

Source

fn remove_row(&mut self, ri: usize) -> bool

Removes an entity for the given row index from the entity container.

If removal is successful, returns true. Otherwise, for instance index is out of bounds, returns false.

§Examples

See ContainEntity document.

Source

fn remove_row_by_value_index(&mut self, vi: usize)

Removes an entity for the given value index from the entity container.

§Panics

Panics if the given value index is out of bounds.

Implementors§

Source§

impl<S> AddEntity for ChunkSparseSet<S>
where S: BuildHasher + Default + Clone + 'static,

Source§

impl<S> AddEntity for SparseSet<S>
where S: BuildHasher + Default + Clone + 'static,