[][src]Struct tiny_ecs::PartMap

pub struct PartMap { /* fields omitted */ }

PartMap is a container type for the parts used by entities

Methods

impl PartMap[src]

pub fn get_part_ref<T: 'static>(&self, id: u32) -> Result<&T, &'static str>[src]

pub fn get_part_mut<T: 'static>(
    &mut self,
    id: u32
) -> Result<&mut T, &'static str>
[src]

Getting a reference to an entity part requires the entity ID and type signature. The type signature is required so that the internal downcast can be done for you.

Example

#[derive(Debug, PartialEq)]
struct Test1 {}

let partmap = entities.get_pmap_ref::<Test1>().unwrap().unwrap();
let part = partmap.get_part_ref::<Test1>(entity_1).unwrap();
assert_eq!(part, &Test1 {});
// or
let part: &Test1 = partmap.get_part_ref(entity_1).unwrap();
assert_eq!(part, &Test1 {});

pub fn iter_ref(&self) -> Iter<u32, Box<dyn Any>>[src]

Returns an immutable iterator over the part map

Example

struct Test1 { x: u32 }
let mut entities = Entities::new(Some(10));

let mut ids = Vec::new();
let id = entities.get_free_slot().unwrap();
assert!(entities.add_part(id, Test1 { x: id }).is_ok());
ids.push(id);

let partmap = entities.get_pmap_ref::<Test1>().unwrap().unwrap();
for (k, v) in partmap.iter_ref() {
    // You must downcast the `Any` type for it to be usable
    let part = v.downcast_ref::<Test1>().unwrap();
    assert!(part.x == *k);
}

pub fn iter_mut(&mut self) -> IterMut<u32, Box<dyn Any>>[src]

Returns a mutable iterator over the part map

Auto Trait Implementations

impl !Send for PartMap

impl !Sync for PartMap

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]