Struct shipyard::AllStoragesViewMut
source · [−]pub struct AllStoragesViewMut<'a>(_);
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
.
Does nothing if the storage already exists.
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)
pub fn add_unique_non_send<T: 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 NonSend and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
sourcepub fn add_unique_non_sync<T: Send + Unique>(&self, component: T)
pub fn add_unique_non_sync<T: Send + 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 NonSync and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
sourcepub fn add_unique_non_send_sync<T: Unique>(&self, component: T)
pub fn add_unique_non_send_sync<T: 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 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
T
storage (exclusive)
Errors
T
storage borrow failed.T
storage 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 retain<S: TupleRetain>(&mut self, entity: EntityId)
pub fn retain<S: TupleRetain>(&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, 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::<SparseSet<U32>>(entity);
sourcepub fn retain_storage(&mut self, entity: EntityId, excluded_storage: &[StorageId])
pub fn retain_storage(&mut self, entity: EntityId, excluded_storage: &[StorageId])
Deletes all components of an entity except the ones passed in S
.
This is identical to retain
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_or_deleted(&mut self)
pub fn clear_all_removed_or_deleted(&mut self)
Clear all deletion and removal tracking data.
sourcepub fn clear_all_removed_or_deleted_older_than_timestamp(
&mut self,
timestamp: TrackingTimestamp
)
pub fn clear_all_removed_or_deleted_older_than_timestamp(
&mut self,
timestamp: TrackingTimestamp
)
Clear all deletion and removal tracking data older than some timestamp.
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<'_>ⓘNotable traits for BulkEntityIter<'a>impl<'a> Iterator for BulkEntityIter<'a> type Item = EntityId;
pub fn bulk_add_entity<T: BulkAddEntity>(
&mut self,
source: T
) -> BulkEntityIter<'_>ⓘNotable traits for BulkEntityIter<'a>impl<'a> Iterator for BulkEntityIter<'a> type Item = EntityId;
Creates multiple new entities and returns an iterator yielding the new EntityId
s.
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
entity
is 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<'s, V: IntoBorrow>(&'s self) -> Result<V, GetStorage> where
V::Borrow: Borrow<'s, View = V> + AllStoragesBorrow<'s>,
pub fn borrow<'s, V: IntoBorrow>(&'s self) -> Result<V, GetStorage> where
V::Borrow: Borrow<'s, View = V> + AllStoragesBorrow<'s>,
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
T
storage - ViewMut<T> for an exclusive access to
T
storage - 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
T
unique storage - UniqueViewMut<T> for an exclusive access to a
T
unique 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
T
storage whereT
isn’tSend
- NonSend<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Send
unique storage. - NonSync<View<T>> for a shared access to a
T
storage whereT
isn’tSync
- NonSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Sync
unique storage. - NonSendSync<View<T>> for a shared access to a
T
storage whereT
isn’tSend
norSync
- NonSendSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
norSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Sync
unique 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<'s, Data, B, R, S: AllSystem<'s, (Data,), B, R>>(
&'s self,
system: S,
data: Data
) -> R
pub fn run_with_data<'s, Data, B, R, S: AllSystem<'s, (Data,), B, R>>(
&'s self,
system: S,
data: Data
) -> R
Borrows the requested storages and runs the function.
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
T
storage - ViewMut<T> for an exclusive access to
T
storage - 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
T
unique storage - UniqueViewMut<T> for an exclusive access to a
T
unique 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
T
storage whereT
isn’tSend
- NonSend<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Send
unique storage. - NonSync<View<T>> for a shared access to a
T
storage whereT
isn’tSync
- NonSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Sync
unique storage. - NonSendSync<View<T>> for a shared access to a
T
storage whereT
isn’tSend
norSync
- NonSendSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
norSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Sync
unique 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<'s, B, R, S: AllSystem<'s, (), B, R>>(&'s self, system: S) -> R
pub fn run<'s, B, R, S: AllSystem<'s, (), B, R>>(&'s self, system: S) -> R
Borrows the requested storages and runs the function.
You can use:
- View<T> for a shared access to
T
storage - ViewMut<T> for an exclusive access to
T
storage - 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
T
unique storage - UniqueViewMut<T> for an exclusive access to a
T
unique 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
T
storage whereT
isn’tSend
- NonSend<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Send
unique storage. - NonSync<View<T>> for a shared access to a
T
storage whereT
isn’tSync
- NonSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Sync
unique storage. - NonSendSync<View<T>> for a shared access to a
T
storage whereT
isn’tSend
norSync
- NonSendSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
norSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Sync
unique 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, 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.
Trait Implementations
sourceimpl AsMut<AllStorages> for AllStoragesViewMut<'_>
impl AsMut<AllStorages> for AllStoragesViewMut<'_>
sourcefn as_mut(&mut self) -> &mut AllStorages
fn as_mut(&mut self) -> &mut AllStorages
Converts this type into a mutable reference of the (usually inferred) input type.
sourceimpl AsRef<AllStorages> for AllStoragesViewMut<'_>
impl AsRef<AllStorages> for AllStoragesViewMut<'_>
sourcefn as_ref(&self) -> &AllStorages
fn as_ref(&self) -> &AllStorages
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl<'a> BorrowInfo for AllStoragesViewMut<'a>
impl<'a> BorrowInfo for AllStoragesViewMut<'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 Deref for AllStoragesViewMut<'_>
impl Deref for AllStoragesViewMut<'_>
type Target = AllStorages
type Target = AllStorages
The resulting type after dereferencing.
sourceimpl DerefMut for AllStoragesViewMut<'_>
impl DerefMut for AllStoragesViewMut<'_>
sourceimpl IntoBorrow for AllStoragesViewMut<'_>
impl IntoBorrow for AllStoragesViewMut<'_>
type Borrow = AllStoragesMutBorrower
type Borrow = AllStoragesMutBorrower
Helper type almost allowing GAT on stable.
Auto Trait Implementations
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
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