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<C, S: AddComponent<C>>(
&self,
entity: EntityId,
storages: S,
component: C,
)
pub fn add_component<C, S: AddComponent<C>>( &self, entity: EntityId, storages: S, component: C, )
Adds component to entity, multiple components can be added at the same time using a tuple.
Entities is only borrowed immutably.
§Panics
entityis 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
entityis 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§
Source§impl Borrow for EntitiesView<'_>
impl Borrow for EntitiesView<'_>
type View<'a> = EntitiesView<'a>
Source§fn borrow<'a>(
all_storages: &'a AllStorages,
all_borrow: Option<SharedBorrow<'a>>,
_last_run: Option<TrackingTimestamp>,
_current: TrackingTimestamp,
) -> Result<Self::View<'a>, GetStorage>
fn borrow<'a>( all_storages: &'a AllStorages, all_borrow: Option<SharedBorrow<'a>>, _last_run: Option<TrackingTimestamp>, _current: TrackingTimestamp, ) -> Result<Self::View<'a>, GetStorage>
This function is where the actual borrowing happens.
Source§impl<'a> BorrowInfo for EntitiesView<'a>
impl<'a> BorrowInfo for EntitiesView<'a>
Source§fn 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
Source§fn enable_tracking(_: &mut Vec<fn(&AllStorages) -> Result<(), GetStorage>>)
fn enable_tracking(_: &mut Vec<fn(&AllStorages) -> Result<(), GetStorage>>)
Enable tracking on the
World where this storage is borrowed.Source§impl Clone for EntitiesView<'_>
impl Clone for EntitiesView<'_>
Source§impl Deref for EntitiesView<'_>
impl Deref for EntitiesView<'_>
Auto Trait Implementations§
impl<'a> Freeze for EntitiesView<'a>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WorldBorrow for Twhere
T: Borrow,
impl<T> WorldBorrow for Twhere
T: Borrow,
type WorldView<'a> = <T as Borrow>::View<'a>
Source§fn world_borrow(
world: &World,
last_run: Option<TrackingTimestamp>,
current: TrackingTimestamp,
) -> Result<<T as WorldBorrow>::WorldView<'_>, GetStorage>
fn world_borrow( world: &World, last_run: Option<TrackingTimestamp>, current: TrackingTimestamp, ) -> Result<<T as WorldBorrow>::WorldView<'_>, GetStorage>
This function is where the actual borrowing happens.