Struct AllStoragesView

Source
pub struct AllStoragesView<'a>(/* private fields */);
Expand description

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

§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 borrow<V: Borrow>(&self) -> Result<V::View<'_>, GetStorage>

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<Data, B, S: AllSystem<(Data,), B>>( &self, system: S, data: Data, ) -> S::Return

Borrows the requested storages, runs the function and evaluates to the function’s return value.
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<B, S: AllSystem<(), B>>(&self, system: S) -> S::Return

Borrows the requested storages, runs the function and evaluates to the function’s return value.

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 memory_usage(&self) -> AllStoragesMemoryUsage<'_>

Displays storages memory information.

Source

pub fn get_tracking_timestamp(&self) -> TrackingTimestamp

Returns a timestamp used to clear tracking information.

Source

pub fn get<T: GetComponent>( &self, entity: EntityId, ) -> Result<T::Out<'_>, GetComponent>

Retrieve components of entity.

Multiple components can be queried at the same time using a tuple.

You can use:

  • &T for a shared access to T component
  • &mut T for an exclusive access to T component
  • This is supported on feature=“thread_local” only:
  • NonSend<&T> for a shared access to a T component where T isn’t Send
  • NonSend<&mut T> for an exclusive access to a T component where T isn’t Send
  • NonSync<&T> for a shared access to a T component where T isn’t Sync
  • NonSync<&mut T> for an exclusive access to a T component where T isn’t Sync
  • NonSendSync<&T> for a shared access to a T component where T isn’t Send nor Sync
  • NonSendSync<&mut T> for an exclusive access to a T component where T isn’t Send nor Sync
§Borrows
§Errors
  • AllStorages borrow failed.
  • Storage borrow failed.
  • Entity does not have the component.
§Example
use shipyard::{AllStoragesViewMut, Component, 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 entity = all_storages.add_entity((USIZE(0), U32(1)));

let (i, j) = all_storages.get::<(&USIZE, &mut U32)>(entity).unwrap();

assert!(*i == &USIZE(0));
assert!(*j == &U32(1));
Source

pub fn get_unique<T: GetUnique>(&self) -> Result<T::Out<'_>, GetStorage>

Retrieve a unique component.

You can use:

  • &T for a shared access to T unique component
  • &mut T for an exclusive access to T unique component
  • This is supported on feature=“thread_local” only:
  • NonSend<&T> for a shared access to a T unique component where T isn’t Send
  • NonSend<&mut T> for an exclusive access to a T unique component where T isn’t Send
  • NonSync<&T> for a shared access to a T unique component where T isn’t Sync
  • NonSync<&mut T> for an exclusive access to a T unique component where T isn’t Sync
  • NonSendSync<&T> for a shared access to a T unique component where T isn’t Send nor Sync
  • NonSendSync<&mut T> for an exclusive access to a T unique component where T isn’t Send nor Sync
§Borrows
§Errors
§Example
use shipyard::{AllStoragesViewMut, Unique, World};

#[derive(Unique, Debug, PartialEq, Eq)]
struct U32(u32);

let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();

all_storages.add_unique(U32(0));

let i = all_storages.get_unique::<&U32>().unwrap();

assert!(*i == U32(0));
Source

pub fn iter<'a, T: IterComponent>(&'a self) -> IntoIterRef<'a, T>

Iterate components.

Multiple components can be iterated at the same time using a tuple.

You can use:

  • &T for a shared access to T component
  • &mut T for an exclusive access to T component
  • This is supported on feature=“thread_local” only:
  • NonSend<&T> for a shared access to a T component where T isn’t Send
  • NonSend<&mut T> for an exclusive access to a T component where T isn’t Send
  • NonSync<&T> for a shared access to a T component where T isn’t Sync
  • NonSync<&mut T> for an exclusive access to a T component where T isn’t Sync
  • NonSendSync<&T> for a shared access to a T component where T isn’t Send nor Sync
  • NonSendSync<&mut T> for an exclusive access to a T component where T isn’t Send nor Sync
§Borrows
§Panics
§Example
use shipyard::{AllStoragesViewMut, Component, 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 entity = all_storages.add_entity((USIZE(0), U32(1)));

let mut iter = all_storages.iter::<(&USIZE, &mut U32)>();

for (i, j) in &mut iter {
    // <-- SNIP -->
}
Source

pub fn on_deletion(&self, f: impl FnMut(EntityId) + Send + Sync + 'static)

Sets the on entity deletion callback.

§Borrows
  • Entities (exclusive)
§Panics
  • Entities borrow failed.

Trait Implementations§

Source§

impl AsRef<AllStorages> for AllStoragesView<'_>

Source§

fn as_ref(&self) -> &AllStorages

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

impl<'a> BorrowInfo for AllStoragesView<'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§

fn enable_tracking(_: &mut Vec<fn(&AllStorages) -> Result<(), GetStorage>>)

Enable tracking on the World where this storage is borrowed.
Source§

impl Clone for AllStoragesView<'_>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for AllStoragesView<'_>

Source§

type Target = AllStorages

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl WorldBorrow for AllStoragesView<'_>

Source§

type WorldView<'a> = AllStoragesView<'a>

Source§

fn world_borrow( world: &World, _last_run: Option<TrackingTimestamp>, _current: TrackingTimestamp, ) -> Result<Self::WorldView<'_>, GetStorage>

This function is where the actual borrowing happens.

Auto Trait Implementations§

§

impl<'a> Freeze for AllStoragesView<'a>

§

impl<'a> !RefUnwindSafe for AllStoragesView<'a>

§

impl<'a> Send for AllStoragesView<'a>

§

impl<'a> Sync for AllStoragesView<'a>

§

impl<'a> Unpin for AllStoragesView<'a>

§

impl<'a> !UnwindSafe for AllStoragesView<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.
Source§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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