pub struct AllStorages { /* private fields */ }
Expand description

Contains all storages present in the World.

Implementations

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);

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();

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();

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);

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);

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.

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();

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));

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, 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)));

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));

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));

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);

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();

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.

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();

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>)>();

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.

Displays storages memory information.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a Ref to the requested S storage. Read more

Returns a Ref to the requested S storage using a StorageId. Read more

Returns a RefMut to the requested S storage.

Returns a RefMut to the requested S storage using a StorageId. Read more

Returns a Ref to the requested S storage and create it if it does not exist. Read more

Returns a Ref to the requested S storage using a StorageId and create it if it does not exist. Read more

Returns a RefMut to the requested S storage and create it if it does not exist. Read more

Returns a RefMut to the requested S storage using a StorageId and create it if it does not exist. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.