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§
Sourcefn to_value_index(&self, ri: usize) -> Option<usize>
fn to_value_index(&self, ri: usize) -> Option<usize>
Converts given row index to value index.
Sourcefn begin_add_row(&mut self)
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.
Sourceunsafe fn add_value(&mut self, ci: usize, val_ptr: NonNull<u8>)
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_rowandAddEntity::end_add_rowfor all components. - Column index
ciis not out of bounds. - Value pointer
val_ptris valid for the component column type. - Value must not be accessed after calling this method even
drop().
§Examples
See ContainEntity document.
Sourceunsafe fn end_add_row(&mut self) -> usize
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.
Sourcefn value_ptr_by_value_index(&self, ci: usize, vi: usize) -> Option<NonNull<u8>>
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.
Sourceunsafe fn begin_remove_row_by_value_index(&mut self, vi: usize)
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.
AddEntity::begin_remove_row_by_value_indexAddEntity::remove_value_by_value_indexAddEntity::drop_value_by_value_indexAddEntity::forget_value_by_value_indexAddEntity::end_remove_row_by_value_index
§Safety
Caller must guarantee
- This method must be followed by
AddEntity::remove_value_by_value_indexandAddEntity::end_remove_row_by_value_index.AddEntity::remove_value_by_value_indexcan be replaced byAddEntity::drop_value_by_value_indexorAddEntity::forget_value_by_value_index. - Value index
viis not out of bounds.
Sourceunsafe fn remove_value_by_value_index(
&mut self,
ci: usize,
vi: usize,
buf: NonNull<u8>,
)
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.
AddEntity::remove_value_by_value_index.AddEntity::drop_value_by_value_index.AddEntity::forget_value_by_value_index.
§Panics
See AddEntity::begin_remove_row_by_value_index document.
§Safety
Caller must guarantee
- This method must be called between
AddEntity::remove_value_by_value_indexandAddEntity::end_remove_row_by_value_indexfor all components. - Column index
ciis not out of bounds. - Value index
viis not out of bounds. - Buffer
bufhas sufficient capacity for the component value.
Sourceunsafe fn drop_value_by_value_index(&mut self, ci: usize, vi: usize)
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.
AddEntity::remove_value_by_value_index.AddEntity::drop_value_by_value_index.AddEntity::forget_value_by_value_index.
§Panics
See AddEntity::begin_remove_row_by_value_index document.
§Safety
Caller must guarantee
- This method must be called between
AddEntity::remove_value_by_value_indexandAddEntity::end_remove_row_by_value_indexfor all components. - Column index
ciis not out of bounds. - Value index
viis not out of bounds.
Sourceunsafe fn forget_value_by_value_index(&mut self, ci: usize, vi: usize)
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.
AddEntity::remove_value_by_value_index.AddEntity::drop_value_by_value_index.AddEntity::forget_value_by_value_index.
§Panics
See AddEntity::begin_remove_row_by_value_index document.
§Safety
Sourceunsafe fn end_remove_row_by_value_index(&mut self, vi: usize)
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
- Caller must have called
AddEntity::begin_remove_row_by_value_indexonce andAddEntity::remove_value_by_value_indexnumber of component columns times before calling to this method for just one entity. - Value index
viis not out of bounds.
Provided Methods§
Sourcefn remove_row(&mut self, ri: usize) -> bool
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.
Sourcefn remove_row_by_value_index(&mut self, vi: usize)
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.