Struct scoundrel::AllStorages
source · [−]pub struct AllStorages { /* private fields */ }
Expand description
Contains all storages present in the World
.
Implementations
sourceimpl AllStorages
impl AllStorages
sourcepub fn add_unique<T>(&self, component: T) where
T: 'static + Send + Sync,
pub fn add_unique<T>(&self, component: T) where
T: 'static + Send + Sync,
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, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(0usize);
sourcepub fn remove_unique<T>(&self) -> Result<T, UniqueRemove> where
T: 'static,
pub fn remove_unique<T>(&self) -> Result<T, UniqueRemove> where
T: 'static,
Removes a unique storage.
Borrows
T
storage (exclusive)
Errors
T
storage borrow failed.T
storage did not exist.
Example
use shipyard::{AllStoragesViewMut, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(0usize);
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, Get, View, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity1 = all_storages.add_entity((0usize, 1u32));
let entity2 = all_storages.add_entity((2usize, 3u32));
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(&2));
assert_eq!(u32s.get(entity2), Ok(&3));
}).unwrap();
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, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((0u32, 1usize));
all_storages.strip(entity);
sourcepub fn retain<S>(&mut self, entity: EntityId) where
S: Retain,
pub fn retain<S>(&mut self, entity: EntityId) where
S: Retain,
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, SparseSet, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((0u32, 1usize));
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 add_entity<T>(&mut self, component: T) -> EntityId where
T: AddComponent,
pub fn add_entity<T>(&mut self, component: T) -> EntityId where
T: AddComponent,
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, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity0 = all_storages.add_entity((0u32,));
let entity1 = all_storages.add_entity((1u32, 11usize));
sourcepub fn bulk_add_entity<T>(&mut self, source: T) -> BulkEntityIter<'_>ⓘNotable traits for BulkEntityIter<'a>impl<'a> Iterator for BulkEntityIter<'a> type Item = EntityId;
where
T: BulkAddEntity,
pub fn bulk_add_entity<T>(&mut self, source: T) -> BulkEntityIter<'_>ⓘNotable traits for BulkEntityIter<'a>impl<'a> Iterator for BulkEntityIter<'a> type Item = EntityId;
where
T: BulkAddEntity,
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, World};
let mut world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity0 = all_storages.bulk_add_entity((0..1).map(|_| {})).next();
let entity1 = all_storages.bulk_add_entity((1..2).map(|i| (i as u32,))).next();
let new_entities = all_storages.bulk_add_entity((10..20).map(|i| (i as u32, i)));
sourcepub fn add_component<T>(&mut self, entity: EntityId, component: T) where
T: AddComponent,
pub fn add_component<T>(&mut self, entity: EntityId, component: T) where
T: AddComponent,
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, World};
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, (0u32,));
// entity already had a `u32` component so it will be replaced
all_storages.add_component(entity, (1u32, 11usize));
sourcepub fn remove<T>(&mut self, entity: EntityId) -> <T as Remove>::Out where
T: Remove,
pub fn remove<T>(&mut self, entity: EntityId) -> <T as Remove>::Out where
T: Remove,
Removes components from an entity.
C
must always be a tuple, even for a single component.
Example
use shipyard::{AllStoragesViewMut, World};
let mut world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((0u32, 1usize));
let (i,) = all_storages.remove::<(u32,)>(entity);
assert_eq!(i, Some(0));
sourcepub fn delete_component<C>(&mut self, entity: EntityId) where
C: DeleteComponent,
pub fn delete_component<C>(&mut self, entity: EntityId) where
C: DeleteComponent,
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, World};
let mut world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((0u32, 1usize));
all_storages.delete_component::<(u32,)>(entity);
sourcepub fn borrow<'s, V>(&'s self) -> Result<V, GetStorage> where
V: IntoBorrow,
<V as IntoBorrow>::Borrow: Borrow<'s>,
<V as IntoBorrow>::Borrow: AllStoragesBorrow<'s>,
<<V as IntoBorrow>::Borrow as Borrow<'s>>::View == V,
pub fn borrow<'s, V>(&'s self) -> Result<V, GetStorage> where
V: IntoBorrow,
<V as IntoBorrow>::Borrow: Borrow<'s>,
<V as IntoBorrow>::Borrow: AllStoragesBorrow<'s>,
<<V as IntoBorrow>::Borrow as Borrow<'s>>::View == V,
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- NonSend: must activate the thread_local feature
- NonSync: must activate the thread_local feature
- NonSendSync: must activate the thread_local feature
Borrows
- Storage (exclusive or shared)
Errors
- Storage borrow failed.
- Unique storage did not exist.
Example
use shipyard::{AllStoragesViewMut, EntitiesView, View, ViewMut, World};
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>(
&'s self,
s: S,
data: Data
) -> Result<R, Run> where
S: AllSystem<'s, (Data,), B, R>,
pub fn run_with_data<'s, Data, B, R, S>(
&'s self,
s: S,
data: Data
) -> Result<R, Run> where
S: AllSystem<'s, (Data,), B, 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- NonSend: must activate the thread_local feature
- NonSync: must activate the thread_local feature
- NonSendSync: must activate the thread_local feature
Borrows
- Storage (exclusive or shared)
Errors
- Storage borrow failed.
- Unique storage did not exist.
- Error returned by user.
sourcepub fn run<'s, B, R, S>(&'s self, s: S) -> Result<R, Run> where
S: AllSystem<'s, (), B, R>,
pub fn run<'s, B, R, S>(&'s self, s: S) -> Result<R, Run> where
S: AllSystem<'s, (), B, 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- NonSend: must activate the thread_local feature
- NonSync: must activate the thread_local feature
- NonSendSync: must activate the thread_local feature
Borrows
- Storage (exclusive or shared)
Errors
- Storage borrow failed.
- Unique storage did not exist.
- Error returned by user.
Example
use shipyard::{AllStoragesViewMut, View, ViewMut, World};
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 --
})
.unwrap();
let i = all_storages.run(sys1).unwrap();
sourcepub fn delete_any<T>(&mut self) where
T: DeleteAny,
pub fn delete_any<T>(&mut self) where
T: DeleteAny,
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, SparseSet, World};
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity0 = all_storages.add_entity((0u32,));
let entity1 = all_storages.add_entity((1usize,));
let entity2 = all_storages.add_entity(("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.
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 CustomStorageAccess for AllStorages
impl CustomStorageAccess for AllStorages
sourcefn custom_storage<S>(&self) -> Result<Ref<'_, &S>, GetStorage> where
S: 'static,
fn custom_storage<S>(&self) -> Result<Ref<'_, &S>, GetStorage> where
S: 'static,
sourcefn custom_storage_by_id(
&self,
storage_id: StorageId
) -> Result<Ref<'_, &dyn Storage>, GetStorage>
fn custom_storage_by_id(
&self,
storage_id: StorageId
) -> Result<Ref<'_, &dyn Storage>, GetStorage>
sourcefn custom_storage_mut<S>(&self) -> Result<RefMut<'_, &mut S>, GetStorage> where
S: 'static,
fn custom_storage_mut<S>(&self) -> Result<RefMut<'_, &mut S>, GetStorage> where
S: 'static,
Returns a RefMut
to the requested S
storage.
sourcefn custom_storage_mut_by_id(
&self,
storage_id: StorageId
) -> Result<RefMut<'_, &mut (dyn Storage + 'static)>, GetStorage>
fn custom_storage_mut_by_id(
&self,
storage_id: StorageId
) -> Result<RefMut<'_, &mut (dyn Storage + 'static)>, GetStorage>
sourcefn custom_storage_or_insert<S, F>(
&self,
f: F
) -> Result<Ref<'_, &S>, GetStorage> where
S: 'static + Storage + Send + Sync,
F: FnOnce() -> S,
fn custom_storage_or_insert<S, F>(
&self,
f: F
) -> Result<Ref<'_, &S>, GetStorage> where
S: 'static + Storage + Send + Sync,
F: FnOnce() -> S,
sourcefn custom_storage_or_insert_by_id<S, F>(
&self,
storage_id: StorageId,
f: F
) -> Result<Ref<'_, &S>, GetStorage> where
S: 'static + Storage + Send + Sync,
F: FnOnce() -> S,
fn custom_storage_or_insert_by_id<S, F>(
&self,
storage_id: StorageId,
f: F
) -> Result<Ref<'_, &S>, GetStorage> where
S: 'static + Storage + Send + Sync,
F: FnOnce() -> S,
sourcefn custom_storage_or_insert_mut<S, F>(
&self,
f: F
) -> Result<RefMut<'_, &mut S>, GetStorage> where
S: 'static + Storage + Send + Sync,
F: FnOnce() -> S,
fn custom_storage_or_insert_mut<S, F>(
&self,
f: F
) -> Result<RefMut<'_, &mut S>, GetStorage> where
S: 'static + Storage + Send + Sync,
F: FnOnce() -> S,
sourceimpl Debug for AllStorages
impl Debug for AllStorages
impl Send for AllStorages
impl Sync for AllStorages
Auto Trait Implementations
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
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.