Struct shipyard::AllStoragesViewMut

source ·
pub struct AllStoragesViewMut<'a>(/* private fields */);
Expand description

Exclusive view over AllStorages.

Methods from Deref<Target = AllStorages>§

source

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

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.

source

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.

source

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.

source

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

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

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

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

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.

source

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

pub fn clear_all_removed_or_deleted(&mut self)

Clear all deletion and removal tracking data.

source

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.

source

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

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

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

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

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

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

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:
§Borrows
  • Storage (exclusive or shared)
§Panics
  • Storage borrow failed.
  • Unique storage did not exist.
  • Error returned by user.
source

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:
§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);
source

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

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.

source

pub fn memory_usage(&self) -> AllStoragesMemoryUsage<'_>

Displays storages memory information.

source

pub fn get_tracking_timestamp(&self) -> TrackingTimestamp

Returns a timestamp used to clear tracking information.

Trait Implementations§

source§

impl AsMut<AllStorages> for AllStoragesViewMut<'_>

source§

fn as_mut(&mut self) -> &mut AllStorages

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

impl AsRef<AllStorages> for AllStoragesViewMut<'_>

source§

fn as_ref(&self) -> &AllStorages

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

impl<'a> BorrowInfo for AllStoragesViewMut<'a>

source§

fn borrow_info(info: &mut Vec<TypeInfo>)

This information is used during workload creation to determine which systems can run in parallel. Read more
source§

impl Deref for AllStoragesViewMut<'_>

§

type Target = AllStorages

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for AllStoragesViewMut<'_>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl IntoBorrow for AllStoragesViewMut<'_>

§

type Borrow = AllStoragesMutBorrower

Helper type almost allowing GAT on stable.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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