pub struct AllStoragesViewMut<'a>(/* private fields */);Expand description
Exclusive view over AllStorages.
Methods from Deref<Target = AllStorages>§
Sourcepub fn add_unique<T: Send + Sync + Unique>(&self, component: T)
pub fn add_unique<T: Send + Sync + Unique>(&self, component: T)
Adds a new unique storage, unique storages store exactly one T at any time.
To access a unique storage value, use UniqueView or UniqueViewMut.
§Example
use shipyard::{AllStoragesViewMut, Unique, World};
#[derive(Unique)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(USIZE(0));Sourcepub fn add_unique_non_send<T: Sync + Unique>(&self, component: T)
Available on crate feature thread_local only.
pub fn add_unique_non_send<T: Sync + Unique>(&self, component: T)
thread_local only.Adds a new unique storage, unique storages store exactly one T at any time.
To access a unique storage value, use NonSend and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
Sourcepub fn add_unique_non_sync<T: Send + Unique>(&self, component: T)
Available on crate feature thread_local only.
pub fn add_unique_non_sync<T: Send + Unique>(&self, component: T)
thread_local only.Adds a new unique storage, unique storages store exactly one T at any time.
To access a unique storage value, use NonSync and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
Sourcepub fn add_unique_non_send_sync<T: Unique>(&self, component: T)
Available on crate feature thread_local only.
pub fn add_unique_non_send_sync<T: Unique>(&self, component: T)
thread_local only.Adds a new unique storage, unique storages store exactly one T at any time.
To access a unique storage value, use NonSync and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
Sourcepub fn remove_unique<T: Unique>(&self) -> Result<T, UniqueRemove>
pub fn remove_unique<T: Unique>(&self) -> Result<T, UniqueRemove>
Removes a unique storage.
§Borrows
Tstorage (exclusive)
§Errors
Tstorage borrow failed.Tstorage did not exist.
§Example
use shipyard::{AllStoragesViewMut, Unique, World};
#[derive(Unique)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(USIZE(0));
let i = all_storages.remove_unique::<USIZE>().unwrap();Sourcepub fn delete_entity(&mut self, entity: EntityId) -> bool
pub fn delete_entity(&mut self, entity: EntityId) -> bool
Delete an entity and all its components.
Returns true if entity was alive.
§Example
use shipyard::{AllStoragesViewMut, Component, Get, View, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity1 = all_storages.add_entity((USIZE(0), U32(1)));
let entity2 = all_storages.add_entity((USIZE(2), U32(3)));
all_storages.delete_entity(entity1);
all_storages.run(|usizes: View<USIZE>, u32s: View<U32>| {
assert!((&usizes).get(entity1).is_err());
assert!((&u32s).get(entity1).is_err());
assert_eq!(usizes.get(entity2), Ok(&USIZE(2)));
assert_eq!(u32s.get(entity2), Ok(&U32(3)));
});Sourcepub fn strip(&mut self, entity: EntityId)
pub fn strip(&mut self, entity: EntityId)
Deletes all components from an entity without deleting it.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((U32(0), USIZE(1)));
all_storages.strip(entity);Sourcepub fn bulk_strip<I: IntoIterator<Item = EntityId>>(&mut self, entities: I)
pub fn bulk_strip<I: IntoIterator<Item = EntityId>>(&mut self, entities: I)
Deletes all components of multiple entities without deleting them.
§Example
use shipyard::{AllStoragesViewMut, Component, View, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let eid0 = all_storages.add_entity((U32(0), USIZE(1)));
let eid1 = all_storages.add_entity(USIZE(10));
let eid2 = all_storages.add_entity(U32(30));
all_storages.bulk_strip([eid0, eid1, eid2]);
let (v_u32, v_usize) = all_storages.borrow::<(View<U32>, View<USIZE>)>().unwrap();
assert_eq!(v_u32.len(), 0);
assert_eq!(v_usize.len(), 0);Sourcepub fn retain_storage<S: TupleRetainStorage>(&mut self, entity: EntityId)
pub fn retain_storage<S: TupleRetainStorage>(&mut self, entity: EntityId)
Deletes all components of an entity except the ones passed in S.
The storage’s type has to be used and not the component.
SparseSet is the default storage.
§Example
use shipyard::{AllStoragesViewMut, Component, sparse_set::SparseSet, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((U32(0), USIZE(1)));
all_storages.retain_storage::<SparseSet<U32>>(entity);Sourcepub fn retain_storage_by_id(
&mut self,
entity: EntityId,
excluded_storage: &[StorageId],
)
pub fn retain_storage_by_id( &mut self, entity: EntityId, excluded_storage: &[StorageId], )
Deletes all components of an entity except the ones passed in S.
This is identical to retain_storage but uses StorageId and not generics.
You should only use this method if you use a custom storage with a runtime id.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Deletes all entities and components in the World.
§Example
use shipyard::{AllStoragesViewMut, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.clear();Sourcepub fn clear_all_removed_and_deleted(&mut self)
pub fn clear_all_removed_and_deleted(&mut self)
Clear all deletion and removal tracking data.
Sourcepub fn clear_all_removed_and_deleted_older_than_timestamp(
&mut self,
timestamp: TrackingTimestamp,
)
pub fn clear_all_removed_and_deleted_older_than_timestamp( &mut self, timestamp: TrackingTimestamp, )
Clear all deletion and removal tracking data older than some timestamp.
Sourcepub fn clear_all_inserted(&mut self)
pub fn clear_all_inserted(&mut self)
Clear all insertion tracking data.
Sourcepub fn clear_all_modified(&mut self)
pub fn clear_all_modified(&mut self)
Clear all modification tracking data.
Sourcepub fn clear_all_inserted_and_modified(&mut self)
pub fn clear_all_inserted_and_modified(&mut self)
Clear all insertion tracking data.
Sourcepub fn retain_mut<T: Component + Send + Sync>(
&mut self,
f: impl FnMut(EntityId, Mut<'_, T>) -> bool,
)
pub fn retain_mut<T: Component + Send + Sync>( &mut self, f: impl FnMut(EntityId, Mut<'_, T>) -> bool, )
Deletes all components for which f(id, Mut<component>) returns false.
§Panics
- Storage borrow failed.
Sourcepub fn add_entity<T: TupleAddComponent>(&mut self, component: T) -> EntityId
pub fn add_entity<T: TupleAddComponent>(&mut self, component: T) -> EntityId
Creates a new entity with the components passed as argument and returns its EntityId.
component must always be a tuple, even for a single component.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity0 = all_storages.add_entity((U32(0),));
let entity1 = all_storages.add_entity((U32(1), USIZE(11)));Sourcepub fn bulk_add_entity<T: BulkAddEntity>(
&mut self,
source: T,
) -> BulkEntityIter<'_> ⓘ
pub fn bulk_add_entity<T: BulkAddEntity>( &mut self, source: T, ) -> BulkEntityIter<'_> ⓘ
Creates multiple new entities and returns an iterator yielding the new EntityIds.
source must always yield a tuple, even for a single component.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let mut world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let new_entities = all_storages.bulk_add_entity((10..20).map(|i| (U32(i as u32), USIZE(i))));Sourcepub fn add_component<T: TupleAddComponent>(
&mut self,
entity: EntityId,
component: T,
)
pub fn add_component<T: TupleAddComponent>( &mut self, entity: EntityId, component: T, )
Adds components to an existing entity.
If the entity already owned a component it will be replaced.
component must always be a tuple, even for a single component.
§Panics
entityis not alive.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let mut world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
// make an empty entity
let entity = all_storages.add_entity(());
all_storages.add_component(entity, (U32(0),));
// entity already had a `u32` component so it will be replaced
all_storages.add_component(entity, (U32(1), USIZE(11)));Sourcepub fn delete_component<C: TupleDelete>(&mut self, entity: EntityId)
pub fn delete_component<C: TupleDelete>(&mut self, entity: EntityId)
Deletes components from an entity. As opposed to remove, delete doesn’t return anything.
C must always be a tuple, even for a single component.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let mut world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((U32(0), USIZE(1)));
all_storages.delete_component::<(U32,)>(entity);Sourcepub fn remove<C: TupleRemove>(&mut self, entity: EntityId) -> C::Out
pub fn remove<C: TupleRemove>(&mut self, entity: EntityId) -> C::Out
Removes components from an entity.
C must always be a tuple, even for a single component.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let mut world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((U32(0), USIZE(1)));
let (i,) = all_storages.remove::<(U32,)>(entity);
assert_eq!(i, Some(U32(0)));Sourcepub fn borrow<V: Borrow>(&self) -> Result<V::View<'_>, GetStorage>
pub fn borrow<V: Borrow>(&self) -> Result<V::View<'_>, GetStorage>
Borrows the requested storage(s), if it doesn’t exist it’ll get created.
You can use a tuple to get multiple storages at once.
You can use:
- View<T> for a shared access to
Tstorage - ViewMut<T> for an exclusive access to
Tstorage - EntitiesView for a shared access to the entity storage
- EntitiesViewMut for an exclusive reference to the entity storage
- UniqueView<T> for a shared access to a
Tunique storage - UniqueViewMut<T> for an exclusive access to a
Tunique storage Option<V>with one or multiple views for fallible access to one or more storages- This is supported on
feature=“thread_local”only:- NonSend<View<T>> for a shared access to a
Tstorage whereTisn’tSend - NonSend<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Sendunique storage. - NonSync<View<T>> for a shared access to a
Tstorage whereTisn’tSync - NonSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Syncunique storage. - NonSendSync<View<T>> for a shared access to a
Tstorage whereTisn’tSendnorSync - NonSendSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSendnorSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Syncunique storage.
- NonSend<View<T>> for a shared access to a
§Borrows
- Storage (exclusive or shared)
§Errors
- Storage borrow failed.
- Unique storage did not exist.
§Example
use shipyard::{AllStoragesViewMut, Component, EntitiesView, View, ViewMut, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let world = World::new();
let all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let u32s = all_storages.borrow::<View<U32>>().unwrap();
let (entities, mut usizes) = all_storages
.borrow::<(EntitiesView, ViewMut<USIZE>)>()
.unwrap();Sourcepub fn run_with_data<Data, B, S: AllSystem<(Data,), B>>(
&self,
system: S,
data: Data,
) -> S::Return
pub fn run_with_data<Data, B, S: AllSystem<(Data,), B>>( &self, system: S, data: Data, ) -> S::Return
Borrows the requested storages, runs the function and evaluates to the function’s return value.
Data can be passed to the function, this always has to be a single type but you can use a tuple if needed.
You can use:
- View<T> for a shared access to
Tstorage - ViewMut<T> for an exclusive access to
Tstorage - EntitiesView for a shared access to the entity storage
- EntitiesViewMut for an exclusive reference to the entity storage
- UniqueView<T> for a shared access to a
Tunique storage - UniqueViewMut<T> for an exclusive access to a
Tunique storage Option<V>with one or multiple views for fallible access to one or more storages- This is supported on
feature=“thread_local”only:- NonSend<View<T>> for a shared access to a
Tstorage whereTisn’tSend - NonSend<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Sendunique storage. - NonSync<View<T>> for a shared access to a
Tstorage whereTisn’tSync - NonSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Syncunique storage. - NonSendSync<View<T>> for a shared access to a
Tstorage whereTisn’tSendnorSync - NonSendSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSendnorSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Syncunique storage.
- NonSend<View<T>> for a shared access to a
§Borrows
- Storage (exclusive or shared)
§Panics
- Storage borrow failed.
- Unique storage did not exist.
- Error returned by user.
Sourcepub fn run<B, S: AllSystem<(), B>>(&self, system: S) -> S::Return
pub fn run<B, S: AllSystem<(), B>>(&self, system: S) -> S::Return
Borrows the requested storages, runs the function and evaluates to the function’s return value.
You can use:
- View<T> for a shared access to
Tstorage - ViewMut<T> for an exclusive access to
Tstorage - EntitiesView for a shared access to the entity storage
- EntitiesViewMut for an exclusive reference to the entity storage
- UniqueView<T> for a shared access to a
Tunique storage - UniqueViewMut<T> for an exclusive access to a
Tunique storage Option<V>with one or multiple views for fallible access to one or more storages- This is supported on
feature=“thread_local”only:- NonSend<View<T>> for a shared access to a
Tstorage whereTisn’tSend - NonSend<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Sendunique storage. - NonSync<View<T>> for a shared access to a
Tstorage whereTisn’tSync - NonSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Syncunique storage. - NonSendSync<View<T>> for a shared access to a
Tstorage whereTisn’tSendnorSync - NonSendSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSendnorSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Syncunique storage.
- NonSend<View<T>> for a shared access to a
§Borrows
- Storage (exclusive or shared)
§Panics
- Storage borrow failed.
- Unique storage did not exist.
- Error returned by user.
§Example
use shipyard::{AllStoragesViewMut, Component, View, ViewMut, World};
#[derive(Component)]
struct I32(i32);
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
fn sys1(i32s: View<I32>) -> i32 {
0
}
let world = World::new();
let all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages
.run(|usizes: View<USIZE>, mut u32s: ViewMut<U32>| {
// -- snip --
});
let i = all_storages.run(sys1);Sourcepub fn delete_any<T: TupleDeleteAny>(&mut self)
pub fn delete_any<T: TupleDeleteAny>(&mut self)
Deletes any entity with at least one of the given type(s).
The storage’s type has to be used and not the component.
SparseSet is the default storage.
§Example
use shipyard::{AllStoragesViewMut, Component, sparse_set::SparseSet, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
#[derive(Component)]
struct STR(&'static str);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity0 = all_storages.add_entity((U32(0),));
let entity1 = all_storages.add_entity((USIZE(1),));
let entity2 = all_storages.add_entity((STR("2"),));
// deletes `entity2`
all_storages.delete_any::<SparseSet<STR>>();
// deletes `entity0` and `entity1`
all_storages.delete_any::<(SparseSet<U32>, SparseSet<USIZE>)>();Sourcepub fn spawn(&mut self, entity: EntityId) -> bool
pub fn spawn(&mut self, entity: EntityId) -> bool
Make the given entity alive.
Does nothing if an entity with a greater generation is already at this index.
Returns true if the entity is successfully spawned.
Sourcepub fn memory_usage(&self) -> AllStoragesMemoryUsage<'_>
pub fn memory_usage(&self) -> AllStoragesMemoryUsage<'_>
Displays storages memory information.
Sourcepub fn get_tracking_timestamp(&self) -> TrackingTimestamp
pub fn get_tracking_timestamp(&self) -> TrackingTimestamp
Returns a timestamp used to clear tracking information.
Sourcepub fn track_insertion<T: TupleTrack>(&mut self) -> &mut AllStorages
pub fn track_insertion<T: TupleTrack>(&mut self) -> &mut AllStorages
Enable insertion tracking for the given components.
Sourcepub fn track_modification<T: TupleTrack>(&mut self) -> &mut AllStorages
pub fn track_modification<T: TupleTrack>(&mut self) -> &mut AllStorages
Enable modification tracking for the given components.
Sourcepub fn track_deletion<T: TupleTrack>(&mut self) -> &mut AllStorages
pub fn track_deletion<T: TupleTrack>(&mut self) -> &mut AllStorages
Enable deletion tracking for the given components.
Sourcepub fn track_removal<T: TupleTrack>(&mut self) -> &mut AllStorages
pub fn track_removal<T: TupleTrack>(&mut self) -> &mut AllStorages
Enable removal tracking for the given components.
Sourcepub fn track_all<T: TupleTrack>(&mut self)
pub fn track_all<T: TupleTrack>(&mut self)
Enable insertion, deletion and removal tracking for the given components.
Sourcepub fn get<T: GetComponent>(
&self,
entity: EntityId,
) -> Result<T::Out<'_>, GetComponent>
pub fn get<T: GetComponent>( &self, entity: EntityId, ) -> Result<T::Out<'_>, GetComponent>
Retrieve components of entity.
Multiple components can be queried at the same time using a tuple.
You can use:
&Tfor a shared access toTcomponent&mut Tfor an exclusive access toTcomponent- This is supported on
feature=“thread_local”only: - NonSend<&T> for a shared access to a
Tcomponent whereTisn’tSend - NonSend<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSend - NonSync<&T> for a shared access to a
Tcomponent whereTisn’tSync - NonSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSync - NonSendSync<&T> for a shared access to a
Tcomponent whereTisn’tSendnorSync - NonSendSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSendnorSync
§Borrows
- AllStorages (shared) + storage (exclusive or shared)
§Errors
- AllStorages borrow failed.
- Storage borrow failed.
- Entity does not have the component.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((USIZE(0), U32(1)));
let (i, j) = all_storages.get::<(&USIZE, &mut U32)>(entity).unwrap();
assert!(*i == &USIZE(0));
assert!(*j == &U32(1));Sourcepub fn get_unique<T: GetUnique>(&self) -> Result<T::Out<'_>, GetStorage>
pub fn get_unique<T: GetUnique>(&self) -> Result<T::Out<'_>, GetStorage>
Retrieve a unique component.
You can use:
&Tfor a shared access toTunique component&mut Tfor an exclusive access toTunique component- This is supported on
feature=“thread_local”only: - NonSend<&T> for a shared access to a
Tunique component whereTisn’tSend - NonSend<&mut T> for an exclusive access to a
Tunique component whereTisn’tSend - NonSync<&T> for a shared access to a
Tunique component whereTisn’tSync - NonSync<&mut T> for an exclusive access to a
Tunique component whereTisn’tSync - NonSendSync<&T> for a shared access to a
Tunique component whereTisn’tSendnorSync - NonSendSync<&mut T> for an exclusive access to a
Tunique component whereTisn’tSendnorSync
§Borrows
- AllStorages (shared) + storage (exclusive or shared)
§Errors
- AllStorages borrow failed.
- Storage borrow failed.
§Example
use shipyard::{AllStoragesViewMut, Unique, World};
#[derive(Unique, Debug, PartialEq, Eq)]
struct U32(u32);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(U32(0));
let i = all_storages.get_unique::<&U32>().unwrap();
assert!(*i == U32(0));Sourcepub fn iter<'a, T: IterComponent>(&'a self) -> IntoIterRef<'a, T>
pub fn iter<'a, T: IterComponent>(&'a self) -> IntoIterRef<'a, T>
Iterate components.
Multiple components can be iterated at the same time using a tuple.
You can use:
&Tfor a shared access toTcomponent&mut Tfor an exclusive access toTcomponent- This is supported on
feature=“thread_local”only: - NonSend<&T> for a shared access to a
Tcomponent whereTisn’tSend - NonSend<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSend - NonSync<&T> for a shared access to a
Tcomponent whereTisn’tSync - NonSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSync - NonSendSync<&T> for a shared access to a
Tcomponent whereTisn’tSendnorSync - NonSendSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSendnorSync
§Borrows
- AllStorages (shared)
§Panics
- AllStorages borrow failed.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((USIZE(0), U32(1)));
let mut iter = all_storages.iter::<(&USIZE, &mut U32)>();
for (i, j) in &mut iter {
// <-- SNIP -->
}Sourcepub fn is_entity_alive(&mut self, entity: EntityId) -> bool
pub fn is_entity_alive(&mut self, entity: EntityId) -> bool
Returns true if entity matches a living entity.
Sourcepub fn move_entity(&mut self, other: &mut AllStorages, entity: EntityId)
pub fn move_entity(&mut self, other: &mut AllStorages, entity: EntityId)
Moves an entity from a World to another.
§Panics
entityis not alive
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let world1 = World::new();
let world2 = World::new();
let mut all_storages1 = world1.borrow::<AllStoragesViewMut>().unwrap();
let mut all_storages2 = world2.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages1.add_entity(USIZE(1));
all_storages1.move_entity(&mut all_storages2, entity);
assert!(!all_storages1.is_entity_alive(entity));
assert_eq!(all_storages2.get::<&USIZE>(entity).as_deref(), Ok(&&USIZE(1)));Sourcepub fn move_components(
&mut self,
other: &mut AllStorages,
from: EntityId,
to: EntityId,
)
pub fn move_components( &mut self, other: &mut AllStorages, from: EntityId, to: EntityId, )
Moves all components from an entity to another in another World.
§Panics
fromis not alivetois not alive
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let world1 = World::new();
let world2 = World::new();
let mut all_storages1 = world1.borrow::<AllStoragesViewMut>().unwrap();
let mut all_storages2 = world2.borrow::<AllStoragesViewMut>().unwrap();
let from = all_storages1.add_entity(USIZE(1));
let to = all_storages2.add_entity(());
all_storages1.move_components(&mut all_storages2, from, to);
assert!(all_storages1.get::<&USIZE>(from).is_err());
assert_eq!(all_storages2.get::<&USIZE>(to).as_deref(), Ok(&&USIZE(1)));Sourcepub fn register_clone<T: TupleClone>(&mut self)
pub fn register_clone<T: TupleClone>(&mut self)
Registers the function to clone these components.
Sourcepub fn clone_storages_to(&self, other: &mut AllStorages)
pub fn clone_storages_to(&self, other: &mut AllStorages)
Clones all storages with a registered clone function from this AllStorages to other.
Tracking is not cloned. Components will count as inserted in other.
Sourcepub fn clone_entity_to(
&self,
other_all_storages: &mut AllStorages,
entity: EntityId,
)
pub fn clone_entity_to( &self, other_all_storages: &mut AllStorages, entity: EntityId, )
Clones entity from this AllStorages to other_all_storages alongside all its with a registered clone function.
Sourcepub fn clone_components_to(
&self,
other_all_storages: &mut AllStorages,
from: EntityId,
to: EntityId,
)
pub fn clone_components_to( &self, other_all_storages: &mut AllStorages, from: EntityId, to: EntityId, )
Clones all components of from entity with a registered clone function from
this AllStorages to other_all_storages’s to entity.
Sourcepub fn serialize<'a, S: Serializer, V: Borrow>(
&'a self,
serializer: S,
) -> Result<S::Ok, Serialize<S>>
Available on crate feature serde1 only.
pub fn serialize<'a, S: Serializer, V: Borrow>( &'a self, serializer: S, ) -> Result<S::Ok, Serialize<S>>
serde1 only.Serializes the view using the provided serializer.
§Example
use shipyard::{AllStoragesViewMut, Component, View, World};
#[derive(Component, serde::Serialize)]
struct Name(String);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let eid1 = all_storages.add_entity(Name("Alice".to_string()));
let mut serialized = Vec::new();
all_storages
.serialize::<_, View<Name>>(&mut serde_json::ser::Serializer::new(&mut serialized))
.unwrap_or_else(|_| panic!());
let serialized_str = String::from_utf8(serialized).unwrap();
assert_eq!(serialized_str, r#"[[{"index":0,"gen":0},"Alice"]]"#);Sourcepub fn deserialize<'a, 'de, D: Deserializer<'de>, V: Borrow>(
&'a self,
deserializer: D,
) -> Result<(), Deserialize<'de, D>>where
V::View<'a>: Deserialize<'de>,
Available on crate feature serde1 only.
pub fn deserialize<'a, 'de, D: Deserializer<'de>, V: Borrow>(
&'a self,
deserializer: D,
) -> Result<(), Deserialize<'de, D>>where
V::View<'a>: Deserialize<'de>,
serde1 only.Deserializes the view using the provided deserializer.
§Example
use shipyard::{AllStoragesViewMut, Component, EntityId, ViewMut, World};
#[derive(Component, serde::Deserialize)]
struct Name(String);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let mut serialized = r#"[[{"index":0,"gen":0},"Alice"]]"#;
all_storages
.deserialize::<_, ViewMut<Name>>(&mut serde_json::de::Deserializer::from_str(serialized))
.unwrap_or_else(|_| panic!());
let alice_eid = EntityId::new_from_index_and_gen(0, 0);
assert_eq!(all_storages.get::<&Name>(alice_eid).unwrap().0, "Alice");
// Careful here, the World is not in a stable state
assert_eq!(all_storages.is_entity_alive(alice_eid), false);
// We can use World::spawn for example to fix the problem
// another solution would be to serialize EntitiesViewMut
all_storages.spawn(alice_eid);
assert_eq!(all_storages.is_entity_alive(alice_eid), true);Trait Implementations§
Source§impl AsMut<AllStorages> for AllStoragesViewMut<'_>
impl AsMut<AllStorages> for AllStoragesViewMut<'_>
Source§fn as_mut(&mut self) -> &mut AllStorages
fn as_mut(&mut self) -> &mut AllStorages
Source§impl AsRef<AllStorages> for AllStoragesViewMut<'_>
impl AsRef<AllStorages> for AllStoragesViewMut<'_>
Source§fn as_ref(&self) -> &AllStorages
fn as_ref(&self) -> &AllStorages
Source§impl<'a> BorrowInfo for AllStoragesViewMut<'a>
impl<'a> BorrowInfo for AllStoragesViewMut<'a>
Source§fn borrow_info(info: &mut Vec<TypeInfo>)
fn borrow_info(info: &mut Vec<TypeInfo>)
Source§fn enable_tracking(_: &mut Vec<fn(&AllStorages) -> Result<(), GetStorage>>)
fn enable_tracking(_: &mut Vec<fn(&AllStorages) -> Result<(), GetStorage>>)
World where this storage is borrowed.Source§impl Deref for AllStoragesViewMut<'_>
impl Deref for AllStoragesViewMut<'_>
Source§impl DerefMut for AllStoragesViewMut<'_>
impl DerefMut for AllStoragesViewMut<'_>
Source§impl WorldBorrow for AllStoragesViewMut<'_>
impl WorldBorrow for AllStoragesViewMut<'_>
type WorldView<'a> = AllStoragesViewMut<'a>
Source§fn world_borrow(
world: &World,
_last_run: Option<TrackingTimestamp>,
_current: TrackingTimestamp,
) -> Result<Self::WorldView<'_>, GetStorage>
fn world_borrow( world: &World, _last_run: Option<TrackingTimestamp>, _current: TrackingTimestamp, ) -> Result<Self::WorldView<'_>, GetStorage>
Auto Trait Implementations§
impl<'a> Freeze for AllStoragesViewMut<'a>
impl<'a> !RefUnwindSafe for AllStoragesViewMut<'a>
impl<'a> !Send for AllStoragesViewMut<'a>
impl<'a> Sync for AllStoragesViewMut<'a>
impl<'a> Unpin for AllStoragesViewMut<'a>
impl<'a> !UnwindSafe for AllStoragesViewMut<'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
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>
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>
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 more