[−][src]Struct tiny_ecs::PartMap
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]
&mut self,
id: u32
) -> Result<&mut T, &'static str>
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
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,