Struct shipyard::EntitiesView
source · [−]pub struct EntitiesView<'a> { /* private fields */ }
Expand description
Shared view over Entities
storage.
Methods from Deref<Target = Entities>
sourcepub fn is_alive(&self, entity: EntityId) -> bool
pub fn is_alive(&self, entity: EntityId) -> bool
Returns true
if entity
matches a living entity.
sourcepub fn add_component<S: AddComponent>(
&self,
entity: EntityId,
storages: S,
component: S::Component
)
pub fn add_component<S: AddComponent>(
&self,
entity: EntityId,
storages: S,
component: S::Component
)
Adds component
to entity
, multiple components can be added at the same time using a tuple.
Entities
is only borrowed immutably.
Panics
entity
is not alive.
Example
use shipyard::{Component, EntitiesView, ViewMut, World};
#[derive(Component)]
struct U32(u32);
let mut world = World::new();
let entity = world.add_entity(());
let (entities, mut u32s) = world.borrow::<(EntitiesView, ViewMut<U32>)>().unwrap();
entities.add_component(entity, &mut u32s, U32(0));
sourcepub fn add_distinct_component<S: AddDistinctComponent>(
&self,
entity: EntityId,
storages: S,
component: S::Component
) -> bool
pub fn add_distinct_component<S: AddDistinctComponent>(
&self,
entity: EntityId,
storages: S,
component: S::Component
) -> bool
Adds component
to entity
, multiple components can be added at the same time using a tuple.
If the entity already has this component, it won’t be replaced. Very useful if you want accurate modification tracking.
Entities
is only borrowed immutably.
Returns true
if the component was added.
Panics
entity
is not alive.
Example
use shipyard::{Component, EntitiesView, ViewMut, World};
#[derive(Component, PartialEq)]
struct U32(u32);
let mut world = World::new();
let entity = world.add_entity(());
let (entities, mut u32s) = world.borrow::<(EntitiesView, ViewMut<U32>)>().unwrap();
assert!(entities.add_distinct_component(entity, &mut u32s, U32(0)));
assert!(!entities.add_distinct_component(entity, &mut u32s, U32(0)));
Trait Implementations
sourceimpl<'a> BorrowInfo for EntitiesView<'a>
impl<'a> BorrowInfo for EntitiesView<'a>
sourcefn borrow_info(info: &mut Vec<TypeInfo>)
fn borrow_info(info: &mut Vec<TypeInfo>)
This information is used during workload creation to determine which systems can run in parallel. Read more
sourceimpl Clone for EntitiesView<'_>
impl Clone for EntitiesView<'_>
sourceimpl Deref for EntitiesView<'_>
impl Deref for EntitiesView<'_>
sourceimpl IntoBorrow for EntitiesView<'_>
impl IntoBorrow for EntitiesView<'_>
type Borrow = EntitiesBorrower
type Borrow = EntitiesBorrower
Helper type almost allowing GAT on stable.
Auto Trait Implementations
impl<'a> RefUnwindSafe for EntitiesView<'a>
impl<'a> Send for EntitiesView<'a>
impl<'a> Sync for EntitiesView<'a>
impl<'a> Unpin for EntitiesView<'a>
impl<'a> UnwindSafe for EntitiesView<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more