Struct shipyard::AllStoragesViewMut[][src]

pub struct AllStoragesViewMut<'a>(_);

Exclusive view over AllStorages.

Methods from Deref<Target = AllStorages>

pub fn add_unique<T: 'static + Send + Sync>(&self, component: T)[src]

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

pub fn add_unique_non_send<T: 'static + Sync>(&self, component: T)[src]

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.

pub fn add_unique_non_sync<T: 'static + Send>(&self, component: T)[src]

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.

pub fn add_unique_non_send_sync<T: 'static>(&self, component: T)[src]

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.

pub fn remove_unique<T: 'static>(&self) -> Result<T, UniqueRemove>[src]

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

pub fn delete_entity(&mut self, entity: EntityId) -> bool[src]

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

pub fn strip(&mut self, entity: EntityId)[src]

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

pub fn retain<S: Retain>(&mut self, entity: EntityId)[src]

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

pub fn retain_storage(
    &mut self,
    entity: EntityId,
    excluded_storage: &[StorageId]
)
[src]

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.

pub fn clear(&mut self)[src]

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

pub fn add_entity<T: AddComponent>(&mut self, component: T) -> EntityId[src]

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

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;
[src]

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

pub fn add_component<T: AddComponent>(&mut self, entity: EntityId, component: T)[src]

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

pub fn remove<T: Remove>(&mut self, entity: EntityId) -> T::Out[src]

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

pub fn delete_component<C: DeleteComponent>(&mut self, entity: EntityId)[src]

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

pub fn borrow<'s, V: IntoBorrow>(&'s self) -> Result<V, GetStorage> where
    V::Borrow: Borrow<'s, View = V> + AllStoragesBorrow<'s>, 
[src]

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

pub fn run_with_data<'s, Data, B, R, S: AllSystem<'s, (Data,), B, R>>(
    &'s self,
    s: S,
    data: Data
) -> Result<R, Run>
[src]

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)

Errors

  • Storage borrow failed.
  • Unique storage did not exist.
  • Error returned by user.

pub fn run<'s, B, R, S: AllSystem<'s, (), B, R>>(
    &'s self,
    s: S
) -> Result<R, Run>
[src]

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)

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

pub fn delete_any<T: DeleteAny>(&mut self)[src]

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

pub fn spawn(&mut self, entity: EntityId) -> bool[src]

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.

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

Displays storages memory information.

Trait Implementations

impl AsMut<AllStorages> for AllStoragesViewMut<'_>[src]

impl AsRef<AllStorages> for AllStoragesViewMut<'_>[src]

impl<'a> BorrowInfo for AllStoragesViewMut<'a>[src]

impl Deref for AllStoragesViewMut<'_>[src]

type Target = AllStorages

The resulting type after dereferencing.

impl DerefMut for AllStoragesViewMut<'_>[src]

impl IntoBorrow for AllStoragesViewMut<'_>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.