Trait BorrowComponent

Source
pub trait BorrowComponent {
    // Required methods
    fn borrow_column(&self, ci: usize) -> BorrowResult<RawGetter>;
    fn borrow_column_mut(&mut self, ci: usize) -> BorrowResult<RawGetter>;
    unsafe fn get_column(&self, ci: usize) -> Option<NonNull<u8>>;
}
Expand description

A trait for borrowing a component column from an entity container.

See ContainEntity for more information.

Required Methods§

Source

fn borrow_column(&self, ci: usize) -> BorrowResult<RawGetter>

Borrows component column for the given column index.

If borrow is successful, returns RawGetter of the component column. Otherwise, returns BorrowError.

§Examples
use my_ecs::prelude::*;
use std::{hash::RandomState, any::TypeId};

#[derive(Component)]
struct Ca;

let mut cont: SparseSet<RandomState> = SparseSet::new();
cont.add_column(tinfo!(Ca));

let col_idx = cont.get_column_index(&TypeId::of::<Ca>()).unwrap();
let getter = cont.borrow_column(col_idx).unwrap();
Source

fn borrow_column_mut(&mut self, ci: usize) -> BorrowResult<RawGetter>

Borrows component column mutably for the given column index.

If borrow is successful, returns RawGetter of the component column. Otherwise, returns BorrowError.

§Examples
use my_ecs::prelude::*;
use std::{hash::RandomState, any::TypeId};

#[derive(Component)]
struct Ca;

let mut cont: SparseSet<RandomState> = SparseSet::new();
cont.add_column(tinfo!(Ca));

let col_idx = cont.get_column_index(&TypeId::of::<Ca>()).unwrap();
let getter = cont.borrow_column_mut(col_idx).unwrap();
Source

unsafe fn get_column(&self, ci: usize) -> Option<NonNull<u8>>

Retrieves component column pointer for the given column index.

If there is not the component column in the entity container, returns None

§Safety

Undefined behavior if exclusive borrow happened before.

Implementors§

Source§

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

Source§

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