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

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.

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.

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.

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

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

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

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

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

Clear all deletion and removal tracking data.

Clear all deletion and removal tracking data older than some timestamp.

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

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

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

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

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

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

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:
Borrows
  • Storage (exclusive or shared)
Panics
  • 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
  • This is supported on feature=“thread_local” only:
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);

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

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.

Returns a timestamp used to clear tracking 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.

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

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

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

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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more