Struct apecs::Components
source · [−]pub struct Components { /* private fields */ }
Expand description
The set of all entities’ components.
Exists in World
by default.
Implementations
sourceimpl Components
impl Components
sourcepub fn insert_bundle<B: IsBundle>(&mut self, entity_id: usize, bundle: B)
pub fn insert_bundle<B: IsBundle>(&mut self, entity_id: usize, bundle: B)
Inserts the bundled components for the given entity.
Panics
- if the bundle’s types are not unique
use apecs::*;
let mut components = Components::default();
components.insert_bundle(0, ("zero", 0u32, 0.0f32));
sourcepub fn insert_component<T: Send + Sync + 'static>(
&mut self,
entity_id: usize,
component: T
) -> Option<T>
pub fn insert_component<T: Send + Sync + 'static>(
&mut self,
entity_id: usize,
component: T
) -> Option<T>
Insert a single component for the given entity.
Returns the previous component, if available.
use apecs::*;
let mut components = Components::default();
components.insert_component(0, "zero");
components.insert_component(0, 0u32);
components.insert_component(0, 0.0f32);
let prev = components.insert_component(0, "none");
assert_eq!(Some("zero"), prev);
sourcepub fn remove<B: IsBundle>(&mut self, entity_id: usize) -> Option<B>
pub fn remove<B: IsBundle>(&mut self, entity_id: usize) -> Option<B>
Remove all components of the given entity and return them as a typed bundle.
Warning
Any components not contained in B
will be discarded.
Panics
Panics if the component types are not unique.
use apecs::*;
let mut components = Components::default();
components.insert_bundle(0, ("zero", 0u32, 0.0f32));
let prev = components.remove::<(u32, f32)>(0);
assert_eq!(Some((0, 0.0)), prev);
sourcepub fn remove_component<T: Send + Sync + 'static>(
&mut self,
entity_id: usize
) -> Option<T>
pub fn remove_component<T: Send + Sync + 'static>(
&mut self,
entity_id: usize
) -> Option<T>
Remove a single component from the given entity, returning it if the entity had a component of that type.
use apecs::*;
let mut components = Components::default();
components.insert_bundle(0, ("zero", 0u32, 0.0f32));
let prev = components.remove_component::<&str>(0);
assert_eq!(Some("zero"), prev);
let dne = components.remove_component::<bool>(0);
assert_eq!(None, dne);
sourceimpl Components
impl Components
sourcepub fn extend<B: IsBundle>(
&mut self,
extension: <B::MutBundle as IsQuery>::ExtensionColumns
)where
B::MutBundle: IsQuery,
pub fn extend<B: IsBundle>(
&mut self,
extension: <B::MutBundle as IsQuery>::ExtensionColumns
)where
B::MutBundle: IsQuery,
Append to the existing set of archetypes in bulk.
This assumes the entries being inserted have unique ids and don’t already exist in the set.
use apecs::*;
let mut components = Components::default();
let a = Box::new((0..10_000).map(|id| Entry::new(id, id as u32)));
let b = Box::new((0..10_000).map(|id| Entry::new(id, id as f32)));
let c = Box::new((0..10_000).map(|id| Entry::new(id, format!("string{}", id))));
let d = Box::new((0..10_000).map(|id| Entry::new(id, id % 2 == 0)));
components.extend::<(u32, f32, String, bool)>((a, b, c, d));
assert_eq!(10_000, components.len());
sourcepub fn query<Q: IsQuery + 'static>(&mut self) -> QueryGuard<'_, Q>
pub fn query<Q: IsQuery + 'static>(&mut self) -> QueryGuard<'_, Q>
Prepare a query.
use apecs::*;
let mut components = Components::default();
components.insert_bundle(0, ("zero", 0.0f32, 0u32));
components.insert_bundle(1, ("zero", 0.0f32, 0u32));
components.insert_bundle(2, ("zero", 0.0f32, 0u32));
for (f, u) in components.query::<(&f32, &u32)>().iter_mut() {
assert_eq!(**f, **u as f32);
}
Trait Implementations
sourceimpl Debug for Components
impl Debug for Components
sourceimpl Default for Components
impl Default for Components
sourceimpl TryDefault for Components
impl TryDefault for Components
fn try_default() -> Option<Self>
Auto Trait Implementations
impl !RefUnwindSafe for Components
impl Send for Components
impl Sync for Components
impl Unpin for Components
impl !UnwindSafe for Components
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more